From 9626ad95c1afc3341992c7913810dad1acdc5581 Mon Sep 17 00:00:00 2001 From: Tyler Fox Date: Sat, 7 Jun 2014 21:59:31 -0700 Subject: [PATCH 01/30] Convert sample project to Swift --- .../project.pbxproj | 53 +++--- TableViewCellWithAutoLayout/AppDelegate.swift | 51 ++++++ TableViewCellWithAutoLayout/RJAppDelegate.h | 34 ---- TableViewCellWithAutoLayout/RJAppDelegate.m | 70 -------- .../TableViewCellWithAutoLayout-Prefix.pch | 1 - .../TableViewController/Model.swift | 49 ++++++ .../TableViewController/RJModel.h | 37 ---- .../TableViewController/RJModel.m | 104 ----------- .../TableViewController/RJTableViewCell.h | 36 ---- .../TableViewController/RJTableViewCell.m | 107 ------------ .../RJTableViewController.h | 31 ---- .../RJTableViewController.m | 163 ------------------ .../TableViewController/TableViewCell.swift | 83 +++++++++ ...leViewCellWithAutoLayout-Bridging-Header.h | 5 + .../TableViewController.swift | 132 ++++++++++++++ TableViewCellWithAutoLayout/main.m | 18 -- 16 files changed, 345 insertions(+), 629 deletions(-) create mode 100644 TableViewCellWithAutoLayout/AppDelegate.swift delete mode 100644 TableViewCellWithAutoLayout/RJAppDelegate.h delete mode 100644 TableViewCellWithAutoLayout/RJAppDelegate.m create mode 100644 TableViewCellWithAutoLayout/TableViewController/Model.swift delete mode 100644 TableViewCellWithAutoLayout/TableViewController/RJModel.h delete mode 100644 TableViewCellWithAutoLayout/TableViewController/RJModel.m delete mode 100644 TableViewCellWithAutoLayout/TableViewController/RJTableViewCell.h delete mode 100644 TableViewCellWithAutoLayout/TableViewController/RJTableViewCell.m delete mode 100644 TableViewCellWithAutoLayout/TableViewController/RJTableViewController.h delete mode 100644 TableViewCellWithAutoLayout/TableViewController/RJTableViewController.m create mode 100644 TableViewCellWithAutoLayout/TableViewController/TableViewCell.swift create mode 100644 TableViewCellWithAutoLayout/TableViewController/TableViewCellWithAutoLayout-Bridging-Header.h create mode 100644 TableViewCellWithAutoLayout/TableViewController/TableViewController.swift delete mode 100644 TableViewCellWithAutoLayout/main.m diff --git a/TableViewCellWithAutoLayout.xcodeproj/project.pbxproj b/TableViewCellWithAutoLayout.xcodeproj/project.pbxproj index b58bc0d..464381b 100644 --- a/TableViewCellWithAutoLayout.xcodeproj/project.pbxproj +++ b/TableViewCellWithAutoLayout.xcodeproj/project.pbxproj @@ -11,17 +11,16 @@ 99BCDCA718008C0000B8E66B /* CoreGraphics.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 99BCDCA618008C0000B8E66B /* CoreGraphics.framework */; }; 99BCDCA918008C0000B8E66B /* UIKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 99BCDCA818008C0000B8E66B /* UIKit.framework */; }; 99BCDCAF18008C0000B8E66B /* InfoPlist.strings in Resources */ = {isa = PBXBuildFile; fileRef = 99BCDCAD18008C0000B8E66B /* InfoPlist.strings */; }; - 99BCDCB118008C0000B8E66B /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = 99BCDCB018008C0000B8E66B /* main.m */; }; - 99BCDCB518008C0000B8E66B /* RJAppDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = 99BCDCB418008C0000B8E66B /* RJAppDelegate.m */; }; 99BCDCB718008C0000B8E66B /* Images.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 99BCDCB618008C0000B8E66B /* Images.xcassets */; }; 99BCDCBE18008C0000B8E66B /* XCTest.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 99BCDCBD18008C0000B8E66B /* XCTest.framework */; }; 99BCDCBF18008C0000B8E66B /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 99BCDCA418008C0000B8E66B /* Foundation.framework */; }; 99BCDCC018008C0000B8E66B /* UIKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 99BCDCA818008C0000B8E66B /* UIKit.framework */; }; 99BCDCC818008C0000B8E66B /* InfoPlist.strings in Resources */ = {isa = PBXBuildFile; fileRef = 99BCDCC618008C0000B8E66B /* InfoPlist.strings */; }; 99BCDCCA18008C0000B8E66B /* TableViewCellWithAutoLayoutTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 99BCDCC918008C0000B8E66B /* TableViewCellWithAutoLayoutTests.m */; }; - 99BCDCDA18008C1700B8E66B /* RJModel.m in Sources */ = {isa = PBXBuildFile; fileRef = 99BCDCD518008C1700B8E66B /* RJModel.m */; }; - 99BCDCDB18008C1700B8E66B /* RJTableViewCell.m in Sources */ = {isa = PBXBuildFile; fileRef = 99BCDCD718008C1700B8E66B /* RJTableViewCell.m */; }; - 99BCDCDC18008C1700B8E66B /* RJTableViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 99BCDCD918008C1700B8E66B /* RJTableViewController.m */; }; + A7C103221943F73D006A9720 /* TableViewCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = A7C103211943F73D006A9720 /* TableViewCell.swift */; }; + A7F5DDAA194408D9008E238B /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = A7F5DDA9194408D9008E238B /* AppDelegate.swift */; }; + A7F5DDAC19440B7B008E238B /* Model.swift in Sources */ = {isa = PBXBuildFile; fileRef = A7F5DDAB19440B7B008E238B /* Model.swift */; }; + A7F5DDAE194417DC008E238B /* TableViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = A7F5DDAD194417DC008E238B /* TableViewController.swift */; }; B147F1841867A715002B0C25 /* UIView+AutoLayout.m in Sources */ = {isa = PBXBuildFile; fileRef = B147F1831867A715002B0C25 /* UIView+AutoLayout.m */; }; /* End PBXBuildFile section */ @@ -42,22 +41,18 @@ 99BCDCA818008C0000B8E66B /* UIKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = UIKit.framework; path = System/Library/Frameworks/UIKit.framework; sourceTree = SDKROOT; }; 99BCDCAC18008C0000B8E66B /* TableViewCellWithAutoLayout-Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = "TableViewCellWithAutoLayout-Info.plist"; sourceTree = ""; }; 99BCDCAE18008C0000B8E66B /* en */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = en; path = en.lproj/InfoPlist.strings; sourceTree = ""; }; - 99BCDCB018008C0000B8E66B /* main.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = main.m; sourceTree = ""; }; 99BCDCB218008C0000B8E66B /* TableViewCellWithAutoLayout-Prefix.pch */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "TableViewCellWithAutoLayout-Prefix.pch"; sourceTree = ""; }; - 99BCDCB318008C0000B8E66B /* RJAppDelegate.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = RJAppDelegate.h; sourceTree = ""; }; - 99BCDCB418008C0000B8E66B /* RJAppDelegate.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = RJAppDelegate.m; sourceTree = ""; }; 99BCDCB618008C0000B8E66B /* Images.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Images.xcassets; sourceTree = ""; }; 99BCDCBC18008C0000B8E66B /* TableViewCellWithAutoLayoutTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = TableViewCellWithAutoLayoutTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; }; 99BCDCBD18008C0000B8E66B /* XCTest.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = XCTest.framework; path = Library/Frameworks/XCTest.framework; sourceTree = DEVELOPER_DIR; }; 99BCDCC518008C0000B8E66B /* TableViewCellWithAutoLayoutTests-Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = "TableViewCellWithAutoLayoutTests-Info.plist"; sourceTree = ""; }; 99BCDCC718008C0000B8E66B /* en */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = en; path = en.lproj/InfoPlist.strings; sourceTree = ""; }; 99BCDCC918008C0000B8E66B /* TableViewCellWithAutoLayoutTests.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = TableViewCellWithAutoLayoutTests.m; sourceTree = ""; }; - 99BCDCD418008C1700B8E66B /* RJModel.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RJModel.h; sourceTree = ""; }; - 99BCDCD518008C1700B8E66B /* RJModel.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = RJModel.m; sourceTree = ""; }; - 99BCDCD618008C1700B8E66B /* RJTableViewCell.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RJTableViewCell.h; sourceTree = ""; }; - 99BCDCD718008C1700B8E66B /* RJTableViewCell.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = RJTableViewCell.m; sourceTree = ""; }; - 99BCDCD818008C1700B8E66B /* RJTableViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RJTableViewController.h; sourceTree = ""; }; - 99BCDCD918008C1700B8E66B /* RJTableViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = RJTableViewController.m; sourceTree = ""; }; + A7C103201943F73C006A9720 /* TableViewCellWithAutoLayout-Bridging-Header.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "TableViewCellWithAutoLayout-Bridging-Header.h"; sourceTree = ""; }; + A7C103211943F73D006A9720 /* TableViewCell.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TableViewCell.swift; sourceTree = ""; }; + A7F5DDA9194408D9008E238B /* AppDelegate.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = ""; }; + A7F5DDAB19440B7B008E238B /* Model.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Model.swift; sourceTree = ""; }; + A7F5DDAD194417DC008E238B /* TableViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TableViewController.swift; sourceTree = ""; }; B147F1821867A715002B0C25 /* UIView+AutoLayout.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "UIView+AutoLayout.h"; sourceTree = ""; }; B147F1831867A715002B0C25 /* UIView+AutoLayout.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "UIView+AutoLayout.m"; sourceTree = ""; }; /* End PBXFileReference section */ @@ -120,8 +115,7 @@ isa = PBXGroup; children = ( B147F1811867A715002B0C25 /* UIView+AutoLayout */, - 99BCDCB318008C0000B8E66B /* RJAppDelegate.h */, - 99BCDCB418008C0000B8E66B /* RJAppDelegate.m */, + A7F5DDA9194408D9008E238B /* AppDelegate.swift */, 99BCDCB618008C0000B8E66B /* Images.xcassets */, 99BCDCD318008C1700B8E66B /* TableViewController */, 99BCDCAB18008C0000B8E66B /* Supporting Files */, @@ -134,7 +128,6 @@ children = ( 99BCDCAC18008C0000B8E66B /* TableViewCellWithAutoLayout-Info.plist */, 99BCDCAD18008C0000B8E66B /* InfoPlist.strings */, - 99BCDCB018008C0000B8E66B /* main.m */, 99BCDCB218008C0000B8E66B /* TableViewCellWithAutoLayout-Prefix.pch */, ); name = "Supporting Files"; @@ -161,12 +154,10 @@ 99BCDCD318008C1700B8E66B /* TableViewController */ = { isa = PBXGroup; children = ( - 99BCDCD418008C1700B8E66B /* RJModel.h */, - 99BCDCD518008C1700B8E66B /* RJModel.m */, - 99BCDCD618008C1700B8E66B /* RJTableViewCell.h */, - 99BCDCD718008C1700B8E66B /* RJTableViewCell.m */, - 99BCDCD818008C1700B8E66B /* RJTableViewController.h */, - 99BCDCD918008C1700B8E66B /* RJTableViewController.m */, + A7C103201943F73C006A9720 /* TableViewCellWithAutoLayout-Bridging-Header.h */, + A7F5DDAB19440B7B008E238B /* Model.swift */, + A7C103211943F73D006A9720 /* TableViewCell.swift */, + A7F5DDAD194417DC008E238B /* TableViewController.swift */, ); path = TableViewController; sourceTree = ""; @@ -276,12 +267,11 @@ isa = PBXSourcesBuildPhase; buildActionMask = 2147483647; files = ( - 99BCDCB518008C0000B8E66B /* RJAppDelegate.m in Sources */, B147F1841867A715002B0C25 /* UIView+AutoLayout.m in Sources */, - 99BCDCDC18008C1700B8E66B /* RJTableViewController.m in Sources */, - 99BCDCB118008C0000B8E66B /* main.m in Sources */, - 99BCDCDA18008C1700B8E66B /* RJModel.m in Sources */, - 99BCDCDB18008C1700B8E66B /* RJTableViewCell.m in Sources */, + A7F5DDAE194417DC008E238B /* TableViewController.swift in Sources */, + A7F5DDAA194408D9008E238B /* AppDelegate.swift in Sources */, + A7F5DDAC19440B7B008E238B /* Model.swift in Sources */, + A7C103221943F73D006A9720 /* TableViewCell.swift in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -402,11 +392,15 @@ buildSettings = { ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; ASSETCATALOG_COMPILER_LAUNCHIMAGE_NAME = LaunchImage; + CLANG_ENABLE_MODULES = YES; GCC_PRECOMPILE_PREFIX_HEADER = YES; GCC_PREFIX_HEADER = "TableViewCellWithAutoLayout/TableViewCellWithAutoLayout-Prefix.pch"; INFOPLIST_FILE = "TableViewCellWithAutoLayout/TableViewCellWithAutoLayout-Info.plist"; IPHONEOS_DEPLOYMENT_TARGET = 8.0; + LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; PRODUCT_NAME = "$(TARGET_NAME)"; + SWIFT_OBJC_BRIDGING_HEADER = "TableViewCellWithAutoLayout/TableViewController/TableViewCellWithAutoLayout-Bridging-Header.h"; + SWIFT_OPTIMIZATION_LEVEL = "-Onone"; WRAPPER_EXTENSION = app; }; name = Debug; @@ -416,11 +410,14 @@ buildSettings = { ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; ASSETCATALOG_COMPILER_LAUNCHIMAGE_NAME = LaunchImage; + CLANG_ENABLE_MODULES = YES; GCC_PRECOMPILE_PREFIX_HEADER = YES; GCC_PREFIX_HEADER = "TableViewCellWithAutoLayout/TableViewCellWithAutoLayout-Prefix.pch"; INFOPLIST_FILE = "TableViewCellWithAutoLayout/TableViewCellWithAutoLayout-Info.plist"; IPHONEOS_DEPLOYMENT_TARGET = 8.0; + LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; PRODUCT_NAME = "$(TARGET_NAME)"; + SWIFT_OBJC_BRIDGING_HEADER = "TableViewCellWithAutoLayout/TableViewController/TableViewCellWithAutoLayout-Bridging-Header.h"; WRAPPER_EXTENSION = app; }; name = Release; diff --git a/TableViewCellWithAutoLayout/AppDelegate.swift b/TableViewCellWithAutoLayout/AppDelegate.swift new file mode 100644 index 0000000..b031fb5 --- /dev/null +++ b/TableViewCellWithAutoLayout/AppDelegate.swift @@ -0,0 +1,51 @@ +// +// AppDelegate.swift +// TableViewCellWithAutoLayout +// +// Copyright (c) 2014 Tyler Fox +// + +import UIKit + +@UIApplicationMain +class AppDelegate: UIResponder, UIApplicationDelegate +{ + var window: UIWindow? + + func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: NSDictionary?) -> Bool + { + // Override point for customization after application launch. + window = UIWindow(frame: UIScreen.mainScreen().bounds) + var viewController = TableViewController(style: .Plain) + window!.rootViewController = UINavigationController(rootViewController: viewController) + window!.makeKeyAndVisible() + return true + } + + func applicationWillResignActive(application: UIApplication) + { + // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state. + // Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game. + } + + func applicationDidEnterBackground(application: UIApplication) + { + // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later. + // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits. + } + + func applicationWillEnterForeground(application: UIApplication) + { + // Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background. + } + + func applicationDidBecomeActive(application: UIApplication) + { + // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface. + } + + func applicationWillTerminate(application: UIApplication) + { + // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:. + } +} diff --git a/TableViewCellWithAutoLayout/RJAppDelegate.h b/TableViewCellWithAutoLayout/RJAppDelegate.h deleted file mode 100644 index 0344e59..0000000 --- a/TableViewCellWithAutoLayout/RJAppDelegate.h +++ /dev/null @@ -1,34 +0,0 @@ -// -// RJAppDelegate.h -// TableViewCellWithAutoLayout -// -// Created by Kevin Muldoon & Tyler Fox on 10/5/13. -// Copyright (c) 2013 RobotJackalope. All rights reserved. -// -// Permission is hereby granted, free of charge, to any person obtaining a copy -// of this software and associated documentation files (the "Software"), to deal -// in the Software without restriction, including without limitation the rights -// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -// copies of the Software, and to permit persons to whom the Software is -// furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included in -// all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -// THE SOFTWARE. -// - -#import - -@interface RJAppDelegate : UIResponder - -@property (strong, nonatomic) UIWindow *window; -@property (strong, nonatomic) UINavigationController *navigationController; - -@end diff --git a/TableViewCellWithAutoLayout/RJAppDelegate.m b/TableViewCellWithAutoLayout/RJAppDelegate.m deleted file mode 100644 index efd5a90..0000000 --- a/TableViewCellWithAutoLayout/RJAppDelegate.m +++ /dev/null @@ -1,70 +0,0 @@ -// -// RJAppDelegate.m -// TableViewCellWithAutoLayout -// -// Created by Kevin Muldoon & Tyler Fox on 10/5/13. -// Copyright (c) 2013 RobotJackalope. All rights reserved. -// -// Permission is hereby granted, free of charge, to any person obtaining a copy -// of this software and associated documentation files (the "Software"), to deal -// in the Software without restriction, including without limitation the rights -// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -// copies of the Software, and to permit persons to whom the Software is -// furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included in -// all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -// THE SOFTWARE. -// - -#import "RJAppDelegate.h" -#import "RJTableViewController.h" - -@implementation RJAppDelegate - -- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions -{ - self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]]; - // Override point for customization after application launch. - RJTableViewController *viewController = [[RJTableViewController alloc] initWithStyle:UITableViewStylePlain]; - self.navigationController = [[UINavigationController alloc] initWithRootViewController:viewController]; - self.window.rootViewController = self.navigationController; - [self.window makeKeyAndVisible]; - return YES; -} - -- (void)applicationWillResignActive:(UIApplication *)application -{ - // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state. - // Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game. -} - -- (void)applicationDidEnterBackground:(UIApplication *)application -{ - // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later. - // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits. -} - -- (void)applicationWillEnterForeground:(UIApplication *)application -{ - // Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background. -} - -- (void)applicationDidBecomeActive:(UIApplication *)application -{ - // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface. -} - -- (void)applicationWillTerminate:(UIApplication *)application -{ - // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:. -} - -@end diff --git a/TableViewCellWithAutoLayout/TableViewCellWithAutoLayout-Prefix.pch b/TableViewCellWithAutoLayout/TableViewCellWithAutoLayout-Prefix.pch index f808fee..743435c 100644 --- a/TableViewCellWithAutoLayout/TableViewCellWithAutoLayout-Prefix.pch +++ b/TableViewCellWithAutoLayout/TableViewCellWithAutoLayout-Prefix.pch @@ -13,5 +13,4 @@ #ifdef __OBJC__ #import #import - #import "UIView+AutoLayout.h" #endif diff --git a/TableViewCellWithAutoLayout/TableViewController/Model.swift b/TableViewCellWithAutoLayout/TableViewController/Model.swift new file mode 100644 index 0000000..483cba6 --- /dev/null +++ b/TableViewCellWithAutoLayout/TableViewController/Model.swift @@ -0,0 +1,49 @@ +// +// Model.swift +// TableViewCellWithAutoLayout +// +// Copyright (c) 2014 Tyler Fox +// + +import Foundation + +class Model +{ + var dataArray: NSMutableArray = [] + + func populate() + { + var fontFamilies = UIFont.familyNames() + for familyName: AnyObject in fontFamilies { + if let familyNameString: String = familyName as? String { + dataArray.addObject(["title": familyNameString, "body": randomLoremIpsum()]) + } + } + } + + func addSingleItem() + { + var fontFamilies = UIFont.familyNames() + + let r = random() % fontFamilies.count + let familyName: AnyObject = fontFamilies[r] + + if let familyNameString: String = familyName as? String { + dataArray.addObject(["title": familyNameString, "body": randomLoremIpsum()]) + } + } + + func randomLoremIpsum() -> String + { + let loremIpsum = "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Praesent non quam ac massa viverra semper. Maecenas mattis justo ac augue volutpat congue. Maecenas laoreet, nulla eu faucibus gravida, felis orci dictum risus, sed sodales sem eros eget risus. Morbi imperdiet sed diam et sodales. Vestibulum ut est id mauris ultrices gravida. Nulla malesuada metus ut erat malesuada, vitae ornare neque semper. Aenean a commodo justo, vel placerat odio. Curabitur vitae consequat tortor. Aenean eu magna ante. Integer tristique elit ac augue laoreet, eget pulvinar lacus dictum. Cras eleifend lacus eget pharetra elementum. Etiam fermentum eu felis eu tristique. Integer eu purus vitae turpis blandit consectetur. Nulla facilisi. Praesent bibendum massa eu metus pulvinar, quis tristique nunc commodo. Ut varius aliquam elit, a tincidunt elit aliquam non. Nunc ac leo purus. Proin condimentum placerat ligula, at tristique neque scelerisque ut. Suspendisse ut congue enim. Integer id sem nisl. Nam dignissim, lectus et dictum sollicitudin, libero augue ullamcorper justo, nec consectetur dolor arcu sed justo. Proin rutrum pharetra lectus, vel gravida ante venenatis sed. Mauris lacinia urna vehicula felis aliquet venenatis. Suspendisse non pretium sapien. Proin id dolor ultricies, dictum augue non, euismod ante. Vivamus et luctus augue, a luctus mi. Maecenas sit amet felis in magna vestibulum viverra vel ut est. Suspendisse potenti. Morbi nec odio pretium lacus laoreet volutpat sit amet at ipsum. Etiam pretium purus vitae tortor auctor, quis cursus metus vehicula. Integer ultricies facilisis arcu, non congue orci pharetra quis. Vivamus pulvinar ligula neque, et vehicula ipsum euismod quis." + + var loremIpsumArray = loremIpsum.componentsSeparatedByString(" ") + + let minimumNumberOfWords = 3 + let r = max(minimumNumberOfWords, random() % loremIpsumArray.count) // get a random number r, where: minimumNumberOfWords <= r <= loremIpsumArray.count + let loremIpsumRandom = loremIpsumArray[0..r] // grab a slice of the lorem ipsum array that contains r number of words + + let loremIpsumText = loremIpsumRandom.reduce("") { "\($0) \($1)" } // join the array of words to make a string + return "\(loremIpsumText)!!!" // append "!!!" so that we always know what the ending characters are + } +} diff --git a/TableViewCellWithAutoLayout/TableViewController/RJModel.h b/TableViewCellWithAutoLayout/TableViewController/RJModel.h deleted file mode 100644 index 5f1ab4d..0000000 --- a/TableViewCellWithAutoLayout/TableViewController/RJModel.h +++ /dev/null @@ -1,37 +0,0 @@ -// -// RJSimpleModel.h -// Collection -// -// Created by Kevin Muldoon & Tyler Fox on 10/5/13. -// Copyright (c) 2013 RobotJackalope. All rights reserved. -// -// Permission is hereby granted, free of charge, to any person obtaining a copy -// of this software and associated documentation files (the "Software"), to deal -// in the Software without restriction, including without limitation the rights -// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -// copies of the Software, and to permit persons to whom the Software is -// furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included in -// all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -// THE SOFTWARE. -// - -#import - -@interface RJModel : NSObject - -@property (nonatomic, strong) NSMutableArray *dataSource; - -- (void)populateDataSource; - -- (void)addSingleItemToDataSource; - -@end diff --git a/TableViewCellWithAutoLayout/TableViewController/RJModel.m b/TableViewCellWithAutoLayout/TableViewController/RJModel.m deleted file mode 100644 index a10b7fd..0000000 --- a/TableViewCellWithAutoLayout/TableViewController/RJModel.m +++ /dev/null @@ -1,104 +0,0 @@ -// -// RJSimpleModel.m -// Collection -// -// Created by Kevin Muldoon & Tyler Fox on 10/5/13. -// Copyright (c) 2013 RobotJackalope. All rights reserved. -// -// Permission is hereby granted, free of charge, to any person obtaining a copy -// of this software and associated documentation files (the "Software"), to deal -// in the Software without restriction, including without limitation the rights -// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -// copies of the Software, and to permit persons to whom the Software is -// furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included in -// all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -// THE SOFTWARE. -// - -#import "RJModel.h" - -@implementation RJModel - -- (id)init { - - if (self = [super init]) { - - } - return self; -} - -- (NSMutableArray *)dataSource -{ - if (!_dataSource) { - _dataSource = [NSMutableArray new]; - } - return _dataSource; -} - -- (void)populateDataSource { - - NSArray *fontFamilies = [NSArray arrayWithArray:[UIFont familyNames]]; - NSMutableArray *result = [[NSMutableArray alloc] initWithCapacity:[fontFamilies count]]; - - for ( NSString *familyName in fontFamilies ) { - NSDictionary *dictionary = [[NSDictionary alloc] initWithObjectsAndKeys:familyName, @"title", - [self randomLorumIpsum], @"body", - @"", @"element2", - @"", @"element3", - @"", @"element4", - nil]; - [result addObject:dictionary]; - } - - self.dataSource = result; - -} - -- (void)addSingleItemToDataSource { - - NSArray *fontFamilies = [NSArray arrayWithArray:[UIFont familyNames]]; - - int r = arc4random() % [fontFamilies count]; - NSString *familyName = [fontFamilies objectAtIndex:r]; - - NSDictionary *dictionary = [[NSDictionary alloc] initWithObjectsAndKeys:familyName, @"title", - [self randomLorumIpsum], @"body", - @"", @"element2", - @"", @"element3", - @"", @"element4", - nil]; - - [self.dataSource addObject:dictionary]; - -} - -- (NSString *)randomLorumIpsum { - - NSString *lorumIpsum = @"Lorem ipsum dolor sit amet, consectetur adipiscing elit. Praesent non quam ac massa viverra semper. Maecenas mattis justo ac augue volutpat congue. Maecenas laoreet, nulla eu faucibus gravida, felis orci dictum risus, sed sodales sem eros eget risus. Morbi imperdiet sed diam et sodales. Vestibulum ut est id mauris ultrices gravida. Nulla malesuada metus ut erat malesuada, vitae ornare neque semper. Aenean a commodo justo, vel placerat odio. Curabitur vitae consequat tortor. Aenean eu magna ante. Integer tristique elit ac augue laoreet, eget pulvinar lacus dictum. Cras eleifend lacus eget pharetra elementum. Etiam fermentum eu felis eu tristique. Integer eu purus vitae turpis blandit consectetur. Nulla facilisi. Praesent bibendum massa eu metus pulvinar, quis tristique nunc commodo. Ut varius aliquam elit, a tincidunt elit aliquam non. Nunc ac leo purus. Proin condimentum placerat ligula, at tristique neque scelerisque ut. Suspendisse ut congue enim. Integer id sem nisl. Nam dignissim, lectus et dictum sollicitudin, libero augue ullamcorper justo, nec consectetur dolor arcu sed justo. Proin rutrum pharetra lectus, vel gravida ante venenatis sed. Mauris lacinia urna vehicula felis aliquet venenatis. Suspendisse non pretium sapien. Proin id dolor ultricies, dictum augue non, euismod ante. Vivamus et luctus augue, a luctus mi. Maecenas sit amet felis in magna vestibulum viverra vel ut est. Suspendisse potenti. Morbi nec odio pretium lacus laoreet volutpat sit amet at ipsum. Etiam pretium purus vitae tortor auctor, quis cursus metus vehicula. Integer ultricies facilisis arcu, non congue orci pharetra quis. Vivamus pulvinar ligula neque, et vehicula ipsum euismod quis."; - - // Split lorum ipsum words into an array - // - NSArray *lorumIpsumArray = [lorumIpsum componentsSeparatedByString:@" "]; - - // Randomly choose words for variable length - // - int r = arc4random() % [lorumIpsumArray count]; - r = MAX(3, r); // no less than 3 words - NSArray *lorumIpsumRandom = [lorumIpsumArray objectsAtIndexes:[NSIndexSet indexSetWithIndexesInRange:NSMakeRange(0, r)]]; - - // Array to string. Adding '!!!' to end of string to ensure all text is visible. - // - return [NSString stringWithFormat:@"%@!!!", [lorumIpsumRandom componentsJoinedByString:@" "]]; - -} - -@end diff --git a/TableViewCellWithAutoLayout/TableViewController/RJTableViewCell.h b/TableViewCellWithAutoLayout/TableViewController/RJTableViewCell.h deleted file mode 100644 index f0bed4f..0000000 --- a/TableViewCellWithAutoLayout/TableViewController/RJTableViewCell.h +++ /dev/null @@ -1,36 +0,0 @@ -// -// RJCell.h -// TableViewController -// -// Created by Kevin Muldoon & Tyler Fox on 10/5/13. -// Copyright (c) 2013 RobotJackalope. All rights reserved. -// -// Permission is hereby granted, free of charge, to any person obtaining a copy -// of this software and associated documentation files (the "Software"), to deal -// in the Software without restriction, including without limitation the rights -// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -// copies of the Software, and to permit persons to whom the Software is -// furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included in -// all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -// THE SOFTWARE. -// - -#import - -@interface RJTableViewCell : UITableViewCell - -@property (strong, nonatomic) IBOutlet UILabel *titleLabel; -@property (strong, nonatomic) IBOutlet UILabel *bodyLabel; - -- (void)updateFonts; - -@end diff --git a/TableViewCellWithAutoLayout/TableViewController/RJTableViewCell.m b/TableViewCellWithAutoLayout/TableViewController/RJTableViewCell.m deleted file mode 100644 index 4773da0..0000000 --- a/TableViewCellWithAutoLayout/TableViewController/RJTableViewCell.m +++ /dev/null @@ -1,107 +0,0 @@ -// -// RJCell.m -// TableViewController -// -// Created by Kevin Muldoon & Tyler Fox on 10/5/13. -// Copyright (c) 2013 RobotJackalope. All rights reserved. -// -// Permission is hereby granted, free of charge, to any person obtaining a copy -// of this software and associated documentation files (the "Software"), to deal -// in the Software without restriction, including without limitation the rights -// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -// copies of the Software, and to permit persons to whom the Software is -// furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included in -// all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -// THE SOFTWARE. -// - -#import "RJTableViewCell.h" - -#define kLabelHorizontalInsets 15.0f -#define kLabelVerticalInsets 10.0f - -@interface RJTableViewCell () - -@property (nonatomic, assign) BOOL didSetupConstraints; - -@end - -@implementation RJTableViewCell - -- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier -{ - self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]; - if (self) { - self.titleLabel = [UILabel newAutoLayoutView]; - [self.titleLabel setLineBreakMode:NSLineBreakByTruncatingTail]; - [self.titleLabel setNumberOfLines:1]; - [self.titleLabel setTextAlignment:NSTextAlignmentLeft]; - [self.titleLabel setTextColor:[UIColor blackColor]]; - self.titleLabel.backgroundColor = [UIColor colorWithRed:0 green:0 blue:1 alpha:0.1]; // light blue - - self.bodyLabel = [UILabel newAutoLayoutView]; - [self.bodyLabel setLineBreakMode:NSLineBreakByTruncatingTail]; - [self.bodyLabel setNumberOfLines:0]; - [self.bodyLabel setTextAlignment:NSTextAlignmentLeft]; - [self.bodyLabel setTextColor:[UIColor darkGrayColor]]; - self.bodyLabel.backgroundColor = [UIColor colorWithRed:1 green:0 blue:0 alpha:0.1]; // light red - - self.contentView.backgroundColor = [UIColor colorWithRed:0 green:1 blue:0 alpha:0.1]; // light green - - [self.contentView addSubview:self.titleLabel]; - [self.contentView addSubview:self.bodyLabel]; - - [self updateFonts]; - } - - return self; -} - -- (void)updateConstraints -{ - [super updateConstraints]; - - if (self.didSetupConstraints) { - return; - } - - // Note: if the constraints you add below require a larger cell size than the current size (which is likely to be the default size {320, 44}), you'll get an exception. - // As a fix, you can temporarily increase the size of the cell's contentView so that this does not occur using code similar to the line below. - // See here for further discussion: https://github.com/Alex311/TableCellWithAutoLayout/commit/bde387b27e33605eeac3465475d2f2ff9775f163#commitcomment-4633188 - // self.contentView.bounds = CGRectMake(0.0f, 0.0f, 99999.0f, 99999.0f); - - [UIView autoSetPriority:UILayoutPriorityRequired forConstraints:^{ - [self.titleLabel autoSetContentCompressionResistancePriorityForAxis:ALAxisVertical]; - }]; - [self.titleLabel autoPinEdgeToSuperviewEdge:ALEdgeTop withInset:kLabelVerticalInsets]; - [self.titleLabel autoPinEdgeToSuperviewEdge:ALEdgeLeading withInset:kLabelHorizontalInsets]; - [self.titleLabel autoPinEdgeToSuperviewEdge:ALEdgeTrailing withInset:kLabelHorizontalInsets]; - - [self.bodyLabel autoPinEdge:ALEdgeTop toEdge:ALEdgeBottom ofView:self.titleLabel withOffset:kLabelVerticalInsets]; - - [UIView autoSetPriority:UILayoutPriorityRequired forConstraints:^{ - [self.bodyLabel autoSetContentCompressionResistancePriorityForAxis:ALAxisVertical]; - }]; - [self.bodyLabel autoPinEdgeToSuperviewEdge:ALEdgeLeading withInset:kLabelHorizontalInsets]; - [self.bodyLabel autoPinEdgeToSuperviewEdge:ALEdgeTrailing withInset:kLabelHorizontalInsets]; - [self.bodyLabel autoPinEdgeToSuperviewEdge:ALEdgeBottom withInset:kLabelVerticalInsets]; - - self.didSetupConstraints = YES; -} - -- (void)updateFonts -{ - self.titleLabel.font = [UIFont preferredFontForTextStyle:UIFontTextStyleHeadline]; - self.bodyLabel.font = [UIFont preferredFontForTextStyle:UIFontTextStyleCaption2]; -} - -@end diff --git a/TableViewCellWithAutoLayout/TableViewController/RJTableViewController.h b/TableViewCellWithAutoLayout/TableViewController/RJTableViewController.h deleted file mode 100644 index 883ae51..0000000 --- a/TableViewCellWithAutoLayout/TableViewController/RJTableViewController.h +++ /dev/null @@ -1,31 +0,0 @@ -// -// RJTableViewController.h -// TableViewController -// -// Created by Kevin Muldoon & Tyler Fox on 10/5/13. -// Copyright (c) 2013 RobotJackalope. All rights reserved. -// -// Permission is hereby granted, free of charge, to any person obtaining a copy -// of this software and associated documentation files (the "Software"), to deal -// in the Software without restriction, including without limitation the rights -// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -// copies of the Software, and to permit persons to whom the Software is -// furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included in -// all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -// THE SOFTWARE. -// - -#import - -@interface RJTableViewController : UITableViewController - -@end diff --git a/TableViewCellWithAutoLayout/TableViewController/RJTableViewController.m b/TableViewCellWithAutoLayout/TableViewController/RJTableViewController.m deleted file mode 100644 index d920481..0000000 --- a/TableViewCellWithAutoLayout/TableViewController/RJTableViewController.m +++ /dev/null @@ -1,163 +0,0 @@ -// -// RJTableViewController.m -// TableViewController -// -// Created by Kevin Muldoon & Tyler Fox on 10/5/13. -// Copyright (c) 2013 RobotJackalope. All rights reserved. -// -// Permission is hereby granted, free of charge, to any person obtaining a copy -// of this software and associated documentation files (the "Software"), to deal -// in the Software without restriction, including without limitation the rights -// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -// copies of the Software, and to permit persons to whom the Software is -// furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included in -// all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -// THE SOFTWARE. -// - -#import "RJTableViewController.h" -#import "RJModel.h" -#import "RJTableViewCell.h" - -static NSString *CellIdentifier = @"CellIdentifier"; - -@interface RJTableViewController () - -@property (strong, nonatomic) RJModel *model; - -@end - -@implementation RJTableViewController - -- (id)initWithStyle:(UITableViewStyle)style -{ - self = [super initWithStyle:style]; - if (self) { - self.model = [[RJModel alloc] init]; - [self.model populateDataSource]; - } - return self; -} - -- (void)viewDidLoad -{ - [super viewDidLoad]; - - self.title = @"iOS 8 Self Sizing Cells"; - self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemTrash target:self action:@selector(clear:)]; - self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAdd target:self action:@selector(addRow:)]; - - self.tableView.allowsSelection = NO; - - [self.tableView registerClass:[RJTableViewCell class] forCellReuseIdentifier:CellIdentifier]; - - // Self-sizing table view cells in iOS 8 require that the rowHeight property of the table view be set to the constant UITableViewAutomaticDimension - self.tableView.rowHeight = UITableViewAutomaticDimension; - - // Self-sizing table view cells in iOS 8 are enabled when the estimatedRowHeight property of the table view is set to a non-zero value. - // Setting the estimated row height prevents the table view from calling tableView:heightForRowAtIndexPath: for every row in the table on first load; - // it will only be called as cells are about to scroll onscreen. This is a major performance optimization. - self.tableView.estimatedRowHeight = 44.0; // set this to whatever your "average" cell height is; it doesn't need to be very accurate -} - -- (void)viewDidAppear:(BOOL)animated -{ - [super viewDidAppear:animated]; - - [[NSNotificationCenter defaultCenter] addObserver:self - selector:@selector(contentSizeCategoryChanged:) - name:UIContentSizeCategoryDidChangeNotification - object:nil]; -} - -- (void)viewDidDisappear:(BOOL)animated -{ - [super viewDidDisappear:animated]; - - [[NSNotificationCenter defaultCenter] removeObserver:self - name:UIContentSizeCategoryDidChangeNotification - object:nil]; -} - -// This method is called when the Dynamic Type user setting changes (from the system Settings app) -- (void)contentSizeCategoryChanged:(NSNotification *)notification -{ - [self.tableView reloadData]; -} - -- (void)clear:(id)sender -{ - NSMutableArray *rowsToDelete = [NSMutableArray new]; - for (NSUInteger i = 0; i < [self.model.dataSource count]; i++) { - [rowsToDelete addObject:[NSIndexPath indexPathForRow:i inSection:0]]; - } - - self.model = [[RJModel alloc] init]; - - [self.tableView deleteRowsAtIndexPaths:rowsToDelete withRowAnimation:UITableViewRowAnimationAutomatic]; - - [self.tableView reloadData]; -} - -- (void)addRow:(id)sender -{ - [self.model addSingleItemToDataSource]; - - NSIndexPath *lastIndexPath = [NSIndexPath indexPathForRow:[self.model.dataSource count] - 1 inSection:0]; - [self.tableView insertRowsAtIndexPaths:@[lastIndexPath] withRowAnimation:UITableViewRowAnimationAutomatic]; -} - -#pragma mark - Table view data source - -- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView -{ - return 1; -} - -- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section -{ - return [self.model.dataSource count]; -} - -- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath -{ - RJTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; - - // Configure the cell for this indexPath - [cell updateFonts]; - NSDictionary *dataSourceItem = [self.model.dataSource objectAtIndex:indexPath.row]; - cell.titleLabel.text = [dataSourceItem valueForKey:@"title"]; - cell.bodyLabel.text = [dataSourceItem valueForKey:@"body"]; - - // Make sure the constraints have been added to this cell, since it may have just been created from scratch - [cell setNeedsUpdateConstraints]; - [cell updateConstraintsIfNeeded]; - - return cell; -} - -/* -- (CGFloat)tableView:(UITableView *)tableView estimatedHeightForRowAtIndexPath:(NSIndexPath *)indexPath -{ - // If you are just returning a constant value from this method, you should instead just set the table view's - // estimatedRowHeight property (in viewDidLoad or similar), which is even faster as the table view won't - // have to call this method for every row in the table view. - // - // Only implement this method if you have row heights that vary by extreme amounts and you notice the scroll indicator - // "jumping" as you scroll the table view when using a constant estimatedRowHeight. If you do implement this method, - // be sure to do as little work as possible to get a reasonably-accurate estimate. - - return 44.0; -} -*/ - -@end diff --git a/TableViewCellWithAutoLayout/TableViewController/TableViewCell.swift b/TableViewCellWithAutoLayout/TableViewController/TableViewCell.swift new file mode 100644 index 0000000..b0891c8 --- /dev/null +++ b/TableViewCellWithAutoLayout/TableViewController/TableViewCell.swift @@ -0,0 +1,83 @@ +// +// TableViewCell.swift +// TableViewCellWithAutoLayout +// +// Copyright (c) 2014 Tyler Fox +// + +import UIKit + +class TableViewCell: UITableViewCell +{ + let labelHorizontalInsets = 15.0 + let labelVerticalInsets = 10.0 + + var didSetupConstraints = false + + var titleLabel: UILabel + var bodyLabel: UILabel + + init(style: UITableViewCellStyle, reuseIdentifier: String!) + { + titleLabel = UILabel.newAutoLayoutView() + titleLabel.lineBreakMode = .ByTruncatingTail + titleLabel.numberOfLines = 1 + titleLabel.textAlignment = .Left + titleLabel.textColor = UIColor.blackColor() + titleLabel.backgroundColor = UIColor(red: 0, green: 0, blue: 1, alpha: 0.1) // light blue + + bodyLabel = UILabel.newAutoLayoutView() + bodyLabel.lineBreakMode = .ByTruncatingTail + bodyLabel.numberOfLines = 0 + bodyLabel.textAlignment = .Left + bodyLabel.textColor = UIColor.darkGrayColor() + bodyLabel.backgroundColor = UIColor(red: 1, green: 0, blue: 0, alpha: 0.1) // light red + + super.init(style: style, reuseIdentifier: reuseIdentifier) + + contentView.addSubview(titleLabel) + contentView.addSubview(bodyLabel) + + contentView.backgroundColor = UIColor(red: 0, green: 1, blue: 0, alpha: 0.1) // light red + + updateFonts() + } + + override func updateConstraints() + { + super.updateConstraints() + + if didSetupConstraints { + return + } + + // Note: if the constraints you add below require a larger cell size than the current size (which is likely to be the default size {320, 44}), you'll get an exception. + // As a fix, you can temporarily increase the size of the cell's contentView so that this does not occur using code similar to the line below. + // See here for further discussion: https://github.com/Alex311/TableCellWithAutoLayout/commit/bde387b27e33605eeac3465475d2f2ff9775f163#commitcomment-4633188 + // contentView.bounds = CGRect(x: 0.0, y: 0.0, width: 99999.0, height: 99999.0) + + UIView.autoSetPriority(1000) { + self.titleLabel.autoSetContentCompressionResistancePriorityForAxis(.Vertical) + } + titleLabel.autoPinEdgeToSuperviewEdge(.Top, withInset: labelVerticalInsets) + titleLabel.autoPinEdgeToSuperviewEdge(.Leading, withInset: labelHorizontalInsets) + titleLabel.autoPinEdgeToSuperviewEdge(.Trailing, withInset: labelHorizontalInsets) + + bodyLabel.autoPinEdge(.Top, toEdge: .Bottom, ofView: titleLabel, withOffset: labelVerticalInsets) + + UIView.autoSetPriority(1000) { + self.bodyLabel.autoSetContentCompressionResistancePriorityForAxis(.Vertical) + } + bodyLabel.autoPinEdgeToSuperviewEdge(.Leading, withInset: labelHorizontalInsets) + bodyLabel.autoPinEdgeToSuperviewEdge(.Trailing, withInset: labelHorizontalInsets) + bodyLabel.autoPinEdgeToSuperviewEdge(.Bottom, withInset: labelVerticalInsets) + + didSetupConstraints = true + } + + func updateFonts() + { + titleLabel.font = UIFont.preferredFontForTextStyle(UIFontTextStyleHeadline) + bodyLabel.font = UIFont.preferredFontForTextStyle(UIFontTextStyleCaption2) + } +} diff --git a/TableViewCellWithAutoLayout/TableViewController/TableViewCellWithAutoLayout-Bridging-Header.h b/TableViewCellWithAutoLayout/TableViewController/TableViewCellWithAutoLayout-Bridging-Header.h new file mode 100644 index 0000000..8280a41 --- /dev/null +++ b/TableViewCellWithAutoLayout/TableViewController/TableViewCellWithAutoLayout-Bridging-Header.h @@ -0,0 +1,5 @@ +// +// Use this file to import your target's public headers that you would like to expose to Swift. +// + +#import "UIView+AutoLayout.h" diff --git a/TableViewCellWithAutoLayout/TableViewController/TableViewController.swift b/TableViewCellWithAutoLayout/TableViewController/TableViewController.swift new file mode 100644 index 0000000..fc0a73f --- /dev/null +++ b/TableViewCellWithAutoLayout/TableViewController/TableViewController.swift @@ -0,0 +1,132 @@ +// +// TableViewController.swift +// TableViewCellWithAutoLayout +// +// Copyright (c) 2014 Tyler Fox +// + +import UIKit + +class TableViewController : UITableViewController +{ + let kCellIdentifier = "CellIdentifier" + + var model = Model() + + init(nibName nibNameOrNil: String!, bundle nibBundleOrNil: NSBundle!) + { + super.init(nibName: nibNameOrNil, bundle: nibBundleOrNil) + } + + init(style: UITableViewStyle) + { + super.init(style: style) + + model.populate() + } + + override func viewDidLoad() + { + super.viewDidLoad() + + title = "iOS 8 Self Sizing Cells" + navigationItem.leftBarButtonItem = UIBarButtonItem(barButtonSystemItem: UIBarButtonSystemItem.Trash, target: self, action: "clear") + navigationItem.rightBarButtonItem = UIBarButtonItem(barButtonSystemItem: UIBarButtonSystemItem.Add, target: self, action: "addRow") + + tableView.allowsSelection = false + + tableView.registerClass(TableViewCell.self, forCellReuseIdentifier: kCellIdentifier) + + // Self-sizing table view cells in iOS 8 require that the rowHeight property of the table view be set to the constant UITableViewAutomaticDimension + tableView.rowHeight = UITableViewAutomaticDimension + + // Self-sizing table view cells in iOS 8 are enabled when the estimatedRowHeight property of the table view is set to a non-zero value. + // Setting the estimated row height prevents the table view from calling tableView:heightForRowAtIndexPath: for every row in the table on first load; + // it will only be called as cells are about to scroll onscreen. This is a major performance optimization. + tableView.estimatedRowHeight = 44.0 // set this to whatever your "average" cell height is; it doesn't need to be very accurate + } + + override func viewDidAppear(animated: Bool) + { + super.viewDidAppear(animated) + + NSNotificationCenter.defaultCenter().addObserver(self, selector: "contentSizeCategoryChanged:", name: UIContentSizeCategoryDidChangeNotification, object: nil) + } + + override func viewDidDisappear(animated: Bool) + { + super.viewDidDisappear(animated) + + NSNotificationCenter.defaultCenter().removeObserver(self, name: UIContentSizeCategoryDidChangeNotification, object: nil) + } + + // This function will be called when the Dynamic Type user setting changes (from the system Settings app) + func contentSizeCategoryChanged(notification: NSNotification) + { + tableView.reloadData() + } + + // Deletes all rows in the table view and replaces the model with a new empty one + func clear() + { + let rowsToDelete: NSMutableArray = [] + for (var i = 0; i < model.dataArray.count; i++) { + rowsToDelete.addObject(NSIndexPath(forRow: i, inSection: 0)) + } + + model = Model() + + tableView.deleteRowsAtIndexPaths(rowsToDelete, withRowAnimation: .Automatic) + } + + // Adds a single row to the table view + func addRow() + { + model.addSingleItem() + + let lastIndexPath = NSIndexPath(forRow: model.dataArray.count - 1, inSection: 0) + tableView.insertRowsAtIndexPaths([lastIndexPath], withRowAnimation: .Automatic) + } + + override func numberOfSectionsInTableView(tableView: UITableView!) -> Int + { + return 1 + } + + override func tableView(tableView: UITableView!, numberOfRowsInSection section: Int) -> Int + { + return model.dataArray.count + } + + override func tableView(tableView: UITableView!, cellForRowAtIndexPath indexPath: NSIndexPath!) -> UITableViewCell! + { + let cell: TableViewCell = tableView.dequeueReusableCellWithIdentifier(kCellIdentifier) as TableViewCell + + // Configure the cell for this indexPath + cell.updateFonts() + let modelDictionary = model.dataArray[indexPath.row] as NSDictionary + cell.titleLabel.text = modelDictionary.valueForKey("title") as String + cell.bodyLabel.text = modelDictionary.valueForKey("body") as String + + // Make sure the constraints have been added to this cell, since it may have just been created from scratch + cell.setNeedsUpdateConstraints() + cell.updateConstraintsIfNeeded() + + return cell + } + + /* + override func tableView(tableView: UITableView!, estimatedHeightForRowAtIndexPath indexPath: NSIndexPath!) -> CGFloat + { + // If you are just returning a constant value from this method, you should instead just set the table view's + // estimatedRowHeight property (in viewDidLoad or similar), which is even faster as the table view won't + // have to call this method for every row in the table view. + // + // Only implement this method if you have row heights that vary by extreme amounts and you notice the scroll indicator + // "jumping" as you scroll the table view when using a constant estimatedRowHeight. If you do implement this method, + // be sure to do as little work as possible to get a reasonably-accurate estimate. + + return 44.0 + } + */ +} diff --git a/TableViewCellWithAutoLayout/main.m b/TableViewCellWithAutoLayout/main.m deleted file mode 100644 index 9989d84..0000000 --- a/TableViewCellWithAutoLayout/main.m +++ /dev/null @@ -1,18 +0,0 @@ -// -// main.m -// TableViewCellWithAutoLayout -// -// Created by Kevin Muldoon on 10/5/13. -// Copyright (c) 2013 RobotJackalope. All rights reserved. -// - -#import - -#import "RJAppDelegate.h" - -int main(int argc, char * argv[]) -{ - @autoreleasepool { - return UIApplicationMain(argc, argv, nil, NSStringFromClass([RJAppDelegate class])); - } -} From cb8913c10d827abdb3edb962f5708a1e90ca0099 Mon Sep 17 00:00:00 2001 From: Tyler Fox Date: Sat, 7 Jun 2014 22:14:21 -0700 Subject: [PATCH 02/30] Update README --- README.md | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index d390e27..42a974c 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,14 @@ TableViewCellWithAutoLayoutiOS8 =========================== -Sample project demonstrating self-sizing table view cells in iOS 8, using Auto Layout in UITableViewCell to achieve dynamic layouts with variable row heights. This project requires Xcode 6 and iOS 8, and is a universal app that will run on iPhone and iPad. +*Note: This sample project requires __Xcode 6__ and __iOS 8__. For a sample project demonstrating the iOS 7 compatible implementation, [click here](https://github.com/smileyborg/TableViewCellWithAutoLayout).* + +Sample project demonstrating self-sizing table view cells in iOS 8, using Auto Layout in UITableViewCell to achieve dynamic layouts with variable row heights. This project is a universal app that will run on iPhone and iPad. This implementation is only compatible with iOS 8 and later. + +There are two branches in this repository: + +1. **master** - A Swift implementation +2. **[objective-c](https://github.com/smileyborg/TableViewCellWithAutoLayoutiOS8/tree/objective-c)** - An Objective-C implementation This sample project displays a table view with cells that each contain a single-line title label and a multi-line body label (each cell's body label displays a random number of lorem ipsum words). From 47c184e793d5f4157f915b82b72427d84943cb9d Mon Sep 17 00:00:00 2001 From: Tyler Fox Date: Sat, 7 Jun 2014 22:17:17 -0700 Subject: [PATCH 03/30] Update README --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 42a974c..1c53b83 100644 --- a/README.md +++ b/README.md @@ -7,7 +7,7 @@ Sample project demonstrating self-sizing table view cells in iOS 8, using Auto L There are two branches in this repository: -1. **master** - A Swift implementation +1. **master** (this branch) - A Swift implementation 2. **[objective-c](https://github.com/smileyborg/TableViewCellWithAutoLayoutiOS8/tree/objective-c)** - An Objective-C implementation This sample project displays a table view with cells that each contain a single-line title label and a multi-line body label (each cell's body label displays a random number of lorem ipsum words). From cd03ca7c22c1c292bb0de5ba4b499d87b1ea83f8 Mon Sep 17 00:00:00 2001 From: Tyler Fox Date: Sat, 7 Jun 2014 22:35:59 -0700 Subject: [PATCH 04/30] Change constraint to be inequality In case the cell is too tall, better to have the extra space go here. --- .../TableViewController/TableViewCell.swift | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/TableViewCellWithAutoLayout/TableViewController/TableViewCell.swift b/TableViewCellWithAutoLayout/TableViewController/TableViewCell.swift index b0891c8..bac9396 100644 --- a/TableViewCellWithAutoLayout/TableViewController/TableViewCell.swift +++ b/TableViewCellWithAutoLayout/TableViewController/TableViewCell.swift @@ -62,9 +62,10 @@ class TableViewCell: UITableViewCell titleLabel.autoPinEdgeToSuperviewEdge(.Top, withInset: labelVerticalInsets) titleLabel.autoPinEdgeToSuperviewEdge(.Leading, withInset: labelHorizontalInsets) titleLabel.autoPinEdgeToSuperviewEdge(.Trailing, withInset: labelHorizontalInsets) - - bodyLabel.autoPinEdge(.Top, toEdge: .Bottom, ofView: titleLabel, withOffset: labelVerticalInsets) - + + // This constraint is an inequality so that if the cell is slightly taller than actually required, extra space will go here + bodyLabel.autoPinEdge(.Top, toEdge: .Bottom, ofView: titleLabel, withOffset: labelVerticalInsets, relation: .GreaterThanOrEqual) + UIView.autoSetPriority(1000) { self.bodyLabel.autoSetContentCompressionResistancePriorityForAxis(.Vertical) } From 0aedb276db5f0a4a59fcfd8de1f72d2f550b9785 Mon Sep 17 00:00:00 2001 From: Tyler Fox Date: Sat, 7 Jun 2014 23:10:38 -0700 Subject: [PATCH 05/30] Apply workarounds for two Apple bugs These are issues with Xcode 6b1 and the iOS 8 SDK first seed. --- .../TableViewController/TableViewCell.swift | 29 +++++++++++-------- 1 file changed, 17 insertions(+), 12 deletions(-) diff --git a/TableViewCellWithAutoLayout/TableViewController/TableViewCell.swift b/TableViewCellWithAutoLayout/TableViewController/TableViewCell.swift index bac9396..525466e 100644 --- a/TableViewCellWithAutoLayout/TableViewController/TableViewCell.swift +++ b/TableViewCellWithAutoLayout/TableViewController/TableViewCell.swift @@ -9,8 +9,8 @@ import UIKit class TableViewCell: UITableViewCell { - let labelHorizontalInsets = 15.0 - let labelVerticalInsets = 10.0 + let kLabelHorizontalInsets = 15.0 + let kLabelVerticalInsets = 10.0 var didSetupConstraints = false @@ -56,22 +56,27 @@ class TableViewCell: UITableViewCell // See here for further discussion: https://github.com/Alex311/TableCellWithAutoLayout/commit/bde387b27e33605eeac3465475d2f2ff9775f163#commitcomment-4633188 // contentView.bounds = CGRect(x: 0.0, y: 0.0, width: 99999.0, height: 99999.0) + // Prevent the two UILabels from being compressed below their intrinsic content height + // FIXME 7-Jun-14 Xcode 6b1: Apple Bug Report Radar #17220525: The UILayoutPriority enum is not compatible with Swift yet! + // As a temporary workaround, we're using the raw value of UILayoutPriorityRequired = 1000 UIView.autoSetPriority(1000) { self.titleLabel.autoSetContentCompressionResistancePriorityForAxis(.Vertical) + self.bodyLabel.autoSetContentCompressionResistancePriorityForAxis(.Vertical) } - titleLabel.autoPinEdgeToSuperviewEdge(.Top, withInset: labelVerticalInsets) - titleLabel.autoPinEdgeToSuperviewEdge(.Leading, withInset: labelHorizontalInsets) - titleLabel.autoPinEdgeToSuperviewEdge(.Trailing, withInset: labelHorizontalInsets) + + // FIXME 7-Jun-14 Xcode 6b1: The Double literals below should refer to the defined constants kLabelHorizontalInsets and kLabelVerticalInsets. + // However, there are currently intermittent compiler failures when the literals are replaced with these constants. For example, 'Could not find member .Top' + + titleLabel.autoPinEdgeToSuperviewEdge(.Top, withInset: 10.0) + titleLabel.autoPinEdgeToSuperviewEdge(.Leading, withInset: 15.0) + titleLabel.autoPinEdgeToSuperviewEdge(.Trailing, withInset: 15.0) // This constraint is an inequality so that if the cell is slightly taller than actually required, extra space will go here - bodyLabel.autoPinEdge(.Top, toEdge: .Bottom, ofView: titleLabel, withOffset: labelVerticalInsets, relation: .GreaterThanOrEqual) + bodyLabel.autoPinEdge(.Top, toEdge: .Bottom, ofView: titleLabel, withOffset: 10.0, relation: .GreaterThanOrEqual) - UIView.autoSetPriority(1000) { - self.bodyLabel.autoSetContentCompressionResistancePriorityForAxis(.Vertical) - } - bodyLabel.autoPinEdgeToSuperviewEdge(.Leading, withInset: labelHorizontalInsets) - bodyLabel.autoPinEdgeToSuperviewEdge(.Trailing, withInset: labelHorizontalInsets) - bodyLabel.autoPinEdgeToSuperviewEdge(.Bottom, withInset: labelVerticalInsets) + bodyLabel.autoPinEdgeToSuperviewEdge(.Leading, withInset: 15.0) + bodyLabel.autoPinEdgeToSuperviewEdge(.Trailing, withInset: 15.0) + bodyLabel.autoPinEdgeToSuperviewEdge(.Bottom, withInset: 10.0) didSetupConstraints = true } From 7bbdfd617bac2b7298a734c00f9f2c3dd423356e Mon Sep 17 00:00:00 2001 From: Tyler Fox Date: Sun, 8 Jun 2014 09:31:33 -0700 Subject: [PATCH 06/30] Rewrite some code to use more pure Swift --- .../TableViewController/Model.swift | 7 ++++--- .../TableViewController/TableViewController.swift | 6 +++--- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/TableViewCellWithAutoLayout/TableViewController/Model.swift b/TableViewCellWithAutoLayout/TableViewController/Model.swift index 483cba6..cc6861a 100644 --- a/TableViewCellWithAutoLayout/TableViewController/Model.swift +++ b/TableViewCellWithAutoLayout/TableViewController/Model.swift @@ -9,14 +9,15 @@ import Foundation class Model { - var dataArray: NSMutableArray = [] + var dataArray: Array<(title:String, body:String)> = Array() func populate() { var fontFamilies = UIFont.familyNames() + for familyName: AnyObject in fontFamilies { if let familyNameString: String = familyName as? String { - dataArray.addObject(["title": familyNameString, "body": randomLoremIpsum()]) + dataArray.append((title: familyNameString, body: randomLoremIpsum())) } } } @@ -29,7 +30,7 @@ class Model let familyName: AnyObject = fontFamilies[r] if let familyNameString: String = familyName as? String { - dataArray.addObject(["title": familyNameString, "body": randomLoremIpsum()]) + dataArray.append((title: familyNameString, body: randomLoremIpsum())) } } diff --git a/TableViewCellWithAutoLayout/TableViewController/TableViewController.swift b/TableViewCellWithAutoLayout/TableViewController/TableViewController.swift index fc0a73f..247bb08 100644 --- a/TableViewCellWithAutoLayout/TableViewController/TableViewController.swift +++ b/TableViewCellWithAutoLayout/TableViewController/TableViewController.swift @@ -104,9 +104,9 @@ class TableViewController : UITableViewController // Configure the cell for this indexPath cell.updateFonts() - let modelDictionary = model.dataArray[indexPath.row] as NSDictionary - cell.titleLabel.text = modelDictionary.valueForKey("title") as String - cell.bodyLabel.text = modelDictionary.valueForKey("body") as String + let modelItem = model.dataArray[indexPath.row] + cell.titleLabel.text = modelItem.title + cell.bodyLabel.text = modelItem.body // Make sure the constraints have been added to this cell, since it may have just been created from scratch cell.setNeedsUpdateConstraints() From 9a70468f5ca3affa61ebea3504191f58337f76c0 Mon Sep 17 00:00:00 2001 From: Tyler Fox Date: Tue, 10 Jun 2014 13:53:18 -0700 Subject: [PATCH 07/30] Resolve issue with constants in Swift By making the (inferred type) Double constants an explicit CGFloat type, they can be used as expected. --- .../TableViewController/TableViewCell.swift | 21 +++++++++---------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/TableViewCellWithAutoLayout/TableViewController/TableViewCell.swift b/TableViewCellWithAutoLayout/TableViewController/TableViewCell.swift index 525466e..0074cbd 100644 --- a/TableViewCellWithAutoLayout/TableViewController/TableViewCell.swift +++ b/TableViewCellWithAutoLayout/TableViewController/TableViewCell.swift @@ -9,8 +9,10 @@ import UIKit class TableViewCell: UITableViewCell { - let kLabelHorizontalInsets = 15.0 - let kLabelVerticalInsets = 10.0 + // The CGFloat type annotation is necessary for these constants because they are passed as arguments to bridged Objective-C methods, + // and without making the type explicit these will be inferred to be type Double which is not compatible. + let kLabelHorizontalInsets: CGFloat = 15.0 + let kLabelVerticalInsets: CGFloat = 10.0 var didSetupConstraints = false @@ -64,19 +66,16 @@ class TableViewCell: UITableViewCell self.bodyLabel.autoSetContentCompressionResistancePriorityForAxis(.Vertical) } - // FIXME 7-Jun-14 Xcode 6b1: The Double literals below should refer to the defined constants kLabelHorizontalInsets and kLabelVerticalInsets. - // However, there are currently intermittent compiler failures when the literals are replaced with these constants. For example, 'Could not find member .Top' - - titleLabel.autoPinEdgeToSuperviewEdge(.Top, withInset: 10.0) - titleLabel.autoPinEdgeToSuperviewEdge(.Leading, withInset: 15.0) - titleLabel.autoPinEdgeToSuperviewEdge(.Trailing, withInset: 15.0) + titleLabel.autoPinEdgeToSuperviewEdge(.Top, withInset: kLabelVerticalInsets) + titleLabel.autoPinEdgeToSuperviewEdge(.Leading, withInset: kLabelHorizontalInsets) + titleLabel.autoPinEdgeToSuperviewEdge(.Trailing, withInset: kLabelHorizontalInsets) // This constraint is an inequality so that if the cell is slightly taller than actually required, extra space will go here bodyLabel.autoPinEdge(.Top, toEdge: .Bottom, ofView: titleLabel, withOffset: 10.0, relation: .GreaterThanOrEqual) - bodyLabel.autoPinEdgeToSuperviewEdge(.Leading, withInset: 15.0) - bodyLabel.autoPinEdgeToSuperviewEdge(.Trailing, withInset: 15.0) - bodyLabel.autoPinEdgeToSuperviewEdge(.Bottom, withInset: 10.0) + bodyLabel.autoPinEdgeToSuperviewEdge(.Leading, withInset: kLabelHorizontalInsets) + bodyLabel.autoPinEdgeToSuperviewEdge(.Trailing, withInset: kLabelHorizontalInsets) + bodyLabel.autoPinEdgeToSuperviewEdge(.Bottom, withInset: kLabelVerticalInsets) didSetupConstraints = true } From ed1373bfa2d84befc184a0cf38cef4b302befca6 Mon Sep 17 00:00:00 2001 From: Tyler Fox Date: Tue, 10 Jun 2014 13:54:32 -0700 Subject: [PATCH 08/30] Minor formatting changes --- .../TableViewController/TableViewCell.swift | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/TableViewCellWithAutoLayout/TableViewController/TableViewCell.swift b/TableViewCellWithAutoLayout/TableViewController/TableViewCell.swift index 0074cbd..ebe7603 100644 --- a/TableViewCellWithAutoLayout/TableViewController/TableViewCell.swift +++ b/TableViewCellWithAutoLayout/TableViewController/TableViewCell.swift @@ -49,9 +49,7 @@ class TableViewCell: UITableViewCell { super.updateConstraints() - if didSetupConstraints { - return - } + if didSetupConstraints { return } // Note: if the constraints you add below require a larger cell size than the current size (which is likely to be the default size {320, 44}), you'll get an exception. // As a fix, you can temporarily increase the size of the cell's contentView so that this does not occur using code similar to the line below. @@ -59,7 +57,7 @@ class TableViewCell: UITableViewCell // contentView.bounds = CGRect(x: 0.0, y: 0.0, width: 99999.0, height: 99999.0) // Prevent the two UILabels from being compressed below their intrinsic content height - // FIXME 7-Jun-14 Xcode 6b1: Apple Bug Report Radar #17220525: The UILayoutPriority enum is not compatible with Swift yet! + // FIXME 7-Jun-14 Xcode 6b1: Apple Bug Report rdar://17220525: The UILayoutPriority enum is not compatible with Swift yet! // As a temporary workaround, we're using the raw value of UILayoutPriorityRequired = 1000 UIView.autoSetPriority(1000) { self.titleLabel.autoSetContentCompressionResistancePriorityForAxis(.Vertical) From 0d7480e478f2a376b54f3e999270cb807b8c237c Mon Sep 17 00:00:00 2001 From: Tyler Fox Date: Wed, 11 Jun 2014 11:23:20 -0700 Subject: [PATCH 09/30] Add example of loading cell from a nib Resolves #2. Thanks to @mbogh for helping put this together! There are still 2 outstanding issues, they seem like Apple bugs at this point: 1. Cells loaded from a nib do not size correctly in iOS 8 when the table view width is not 320pts (e.g. landscape iPhone, any iPad). (Programmatically loaded cells work fine.) 2. Changing the Dynamic Type slider while the app is running does not fire the UIContentSizeCategoryDidChangeNotification, meaning the app does not respond by updating its UI until it is killed and launched again. --- .../project.pbxproj | 32 ++++++++-- .../NibTableViewCell.swift | 27 +++++++++ .../TableViewController/NibTableViewCell.xib | 48 +++++++++++++++ .../TableViewController/TableViewCell.swift | 2 +- .../TableViewController.swift | 59 ++++++++++++++----- 5 files changed, 146 insertions(+), 22 deletions(-) create mode 100644 TableViewCellWithAutoLayout/TableViewController/NibTableViewCell.swift create mode 100644 TableViewCellWithAutoLayout/TableViewController/NibTableViewCell.xib diff --git a/TableViewCellWithAutoLayout.xcodeproj/project.pbxproj b/TableViewCellWithAutoLayout.xcodeproj/project.pbxproj index 464381b..56893a0 100644 --- a/TableViewCellWithAutoLayout.xcodeproj/project.pbxproj +++ b/TableViewCellWithAutoLayout.xcodeproj/project.pbxproj @@ -7,6 +7,8 @@ objects = { /* Begin PBXBuildFile section */ + 5A3B25361945F89500838EF4 /* NibTableViewCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5A3B25351945F89500838EF4 /* NibTableViewCell.swift */; }; + 5A3B25381945F8AC00838EF4 /* NibTableViewCell.xib in Resources */ = {isa = PBXBuildFile; fileRef = 5A3B25371945F8AC00838EF4 /* NibTableViewCell.xib */; }; 99BCDCA518008C0000B8E66B /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 99BCDCA418008C0000B8E66B /* Foundation.framework */; }; 99BCDCA718008C0000B8E66B /* CoreGraphics.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 99BCDCA618008C0000B8E66B /* CoreGraphics.framework */; }; 99BCDCA918008C0000B8E66B /* UIKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 99BCDCA818008C0000B8E66B /* UIKit.framework */; }; @@ -35,6 +37,8 @@ /* End PBXContainerItemProxy section */ /* Begin PBXFileReference section */ + 5A3B25351945F89500838EF4 /* NibTableViewCell.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = NibTableViewCell.swift; sourceTree = ""; }; + 5A3B25371945F8AC00838EF4 /* NibTableViewCell.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; path = NibTableViewCell.xib; sourceTree = ""; }; 99BCDCA118008C0000B8E66B /* TableViewCellWithAutoLayout.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = TableViewCellWithAutoLayout.app; sourceTree = BUILT_PRODUCTS_DIR; }; 99BCDCA418008C0000B8E66B /* Foundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Foundation.framework; path = System/Library/Frameworks/Foundation.framework; sourceTree = SDKROOT; }; 99BCDCA618008C0000B8E66B /* CoreGraphics.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = CoreGraphics.framework; path = System/Library/Frameworks/CoreGraphics.framework; sourceTree = SDKROOT; }; @@ -156,12 +160,30 @@ children = ( A7C103201943F73C006A9720 /* TableViewCellWithAutoLayout-Bridging-Header.h */, A7F5DDAB19440B7B008E238B /* Model.swift */, - A7C103211943F73D006A9720 /* TableViewCell.swift */, A7F5DDAD194417DC008E238B /* TableViewController.swift */, + B13F6E9E1947D6DE00FF3B42 /* Programmatic */, + B13F6E9F1947D6EB00FF3B42 /* Interface Builder */, ); path = TableViewController; sourceTree = ""; }; + B13F6E9E1947D6DE00FF3B42 /* Programmatic */ = { + isa = PBXGroup; + children = ( + A7C103211943F73D006A9720 /* TableViewCell.swift */, + ); + name = Programmatic; + sourceTree = ""; + }; + B13F6E9F1947D6EB00FF3B42 /* Interface Builder */ = { + isa = PBXGroup; + children = ( + 5A3B25351945F89500838EF4 /* NibTableViewCell.swift */, + 5A3B25371945F8AC00838EF4 /* NibTableViewCell.xib */, + ); + name = "Interface Builder"; + sourceTree = ""; + }; B147F1811867A715002B0C25 /* UIView+AutoLayout */ = { isa = PBXGroup; children = ( @@ -216,7 +238,7 @@ isa = PBXProject; attributes = { CLASSPREFIX = RJ; - LastUpgradeCheck = 0500; + LastUpgradeCheck = 0600; ORGANIZATIONNAME = RobotJackalope; TargetAttributes = { 99BCDCBB18008C0000B8E66B = { @@ -248,6 +270,7 @@ buildActionMask = 2147483647; files = ( 99BCDCAF18008C0000B8E66B /* InfoPlist.strings in Resources */, + 5A3B25381945F8AC00838EF4 /* NibTableViewCell.xib in Resources */, 99BCDCB718008C0000B8E66B /* Images.xcassets in Resources */, ); runOnlyForDeploymentPostprocessing = 0; @@ -268,6 +291,7 @@ buildActionMask = 2147483647; files = ( B147F1841867A715002B0C25 /* UIView+AutoLayout.m in Sources */, + 5A3B25361945F89500838EF4 /* NibTableViewCell.swift in Sources */, A7F5DDAE194417DC008E238B /* TableViewController.swift in Sources */, A7F5DDAA194408D9008E238B /* AppDelegate.swift in Sources */, A7F5DDAC19440B7B008E238B /* Model.swift in Sources */, @@ -317,7 +341,6 @@ isa = XCBuildConfiguration; buildSettings = { ALWAYS_SEARCH_USER_PATHS = NO; - ARCHS = "$(ARCHS_STANDARD_INCLUDING_64_BIT)"; CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; CLANG_CXX_LIBRARY = "libc++"; CLANG_ENABLE_MODULES = YES; @@ -357,7 +380,6 @@ isa = XCBuildConfiguration; buildSettings = { ALWAYS_SEARCH_USER_PATHS = NO; - ARCHS = "$(ARCHS_STANDARD_INCLUDING_64_BIT)"; CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; CLANG_CXX_LIBRARY = "libc++"; CLANG_ENABLE_MODULES = YES; @@ -425,7 +447,6 @@ 99BCDCD118008C0000B8E66B /* Debug */ = { isa = XCBuildConfiguration; buildSettings = { - ARCHS = "$(ARCHS_STANDARD_INCLUDING_64_BIT)"; BUNDLE_LOADER = "$(BUILT_PRODUCTS_DIR)/TableViewCellWithAutoLayout.app/TableViewCellWithAutoLayout"; FRAMEWORK_SEARCH_PATHS = ( "$(SDKROOT)/Developer/Library/Frameworks", @@ -448,7 +469,6 @@ 99BCDCD218008C0000B8E66B /* Release */ = { isa = XCBuildConfiguration; buildSettings = { - ARCHS = "$(ARCHS_STANDARD_INCLUDING_64_BIT)"; BUNDLE_LOADER = "$(BUILT_PRODUCTS_DIR)/TableViewCellWithAutoLayout.app/TableViewCellWithAutoLayout"; FRAMEWORK_SEARCH_PATHS = ( "$(SDKROOT)/Developer/Library/Frameworks", diff --git a/TableViewCellWithAutoLayout/TableViewController/NibTableViewCell.swift b/TableViewCellWithAutoLayout/TableViewController/NibTableViewCell.swift new file mode 100644 index 0000000..fc985c6 --- /dev/null +++ b/TableViewCellWithAutoLayout/TableViewController/NibTableViewCell.swift @@ -0,0 +1,27 @@ +// +// NibTableViewCell.swift +// TableViewCellWithAutoLayout +// +// Copyright (c) 2014 Morten Bøgh +// + +import UIKit + +class NibTableViewCell: UITableViewCell +{ + @IBOutlet var titleLabel: UILabel + @IBOutlet var bodyLabel: UILabel + + override func awakeFromNib() + { + super.awakeFromNib() + + updateFonts() + } + + func updateFonts() + { + titleLabel.font = UIFont.preferredFontForTextStyle(UIFontTextStyleHeadline) + bodyLabel.font = UIFont.preferredFontForTextStyle(UIFontTextStyleCaption2) + } +} diff --git a/TableViewCellWithAutoLayout/TableViewController/NibTableViewCell.xib b/TableViewCellWithAutoLayout/TableViewController/NibTableViewCell.xib new file mode 100644 index 0000000..3d7ff40 --- /dev/null +++ b/TableViewCellWithAutoLayout/TableViewController/NibTableViewCell.xib @@ -0,0 +1,48 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/TableViewCellWithAutoLayout/TableViewController/TableViewCell.swift b/TableViewCellWithAutoLayout/TableViewController/TableViewCell.swift index ebe7603..de4171d 100644 --- a/TableViewCellWithAutoLayout/TableViewController/TableViewCell.swift +++ b/TableViewCellWithAutoLayout/TableViewController/TableViewCell.swift @@ -40,7 +40,7 @@ class TableViewCell: UITableViewCell contentView.addSubview(titleLabel) contentView.addSubview(bodyLabel) - contentView.backgroundColor = UIColor(red: 0, green: 1, blue: 0, alpha: 0.1) // light red + contentView.backgroundColor = UIColor(red: 0, green: 1, blue: 0, alpha: 0.1) // light green updateFonts() } diff --git a/TableViewCellWithAutoLayout/TableViewController/TableViewController.swift b/TableViewCellWithAutoLayout/TableViewController/TableViewController.swift index 247bb08..a1ecc96 100644 --- a/TableViewCellWithAutoLayout/TableViewController/TableViewController.swift +++ b/TableViewCellWithAutoLayout/TableViewController/TableViewController.swift @@ -7,7 +7,7 @@ import UIKit -class TableViewController : UITableViewController +class TableViewController: UITableViewController { let kCellIdentifier = "CellIdentifier" @@ -35,7 +35,18 @@ class TableViewController : UITableViewController tableView.allowsSelection = false - tableView.registerClass(TableViewCell.self, forCellReuseIdentifier: kCellIdentifier) + + + /****************************************************************** + SWITCH BETWEEN PROGRAMMATIC AND INTERFACE BUILDER LOADED CELLS + + Uncomment ONE of the two lines below to switch between approaches. + Make sure that the other line commented out - don't uncomment both! + *******************************************************************/ + tableView.registerClass(TableViewCell.self, forCellReuseIdentifier: kCellIdentifier) // uncomment this line to load table view cells programmatically +// tableView.registerNib(UINib(nibName: "NibTableViewCell", bundle: NSBundle.mainBundle()), forCellReuseIdentifier: kCellIdentifier) // uncomment this line to load table view cells from IB + + // Self-sizing table view cells in iOS 8 require that the rowHeight property of the table view be set to the constant UITableViewAutomaticDimension tableView.rowHeight = UITableViewAutomaticDimension @@ -100,19 +111,37 @@ class TableViewController : UITableViewController override func tableView(tableView: UITableView!, cellForRowAtIndexPath indexPath: NSIndexPath!) -> UITableViewCell! { - let cell: TableViewCell = tableView.dequeueReusableCellWithIdentifier(kCellIdentifier) as TableViewCell - - // Configure the cell for this indexPath - cell.updateFonts() - let modelItem = model.dataArray[indexPath.row] - cell.titleLabel.text = modelItem.title - cell.bodyLabel.text = modelItem.body - - // Make sure the constraints have been added to this cell, since it may have just been created from scratch - cell.setNeedsUpdateConstraints() - cell.updateConstraintsIfNeeded() - - return cell + // This will be the case for programmatically loaded cells (see viewDidLoad to switch approaches) + if let cell: TableViewCell = tableView.dequeueReusableCellWithIdentifier(kCellIdentifier) as? TableViewCell { + // Configure the cell for this indexPath + cell.updateFonts() + let modelItem = model.dataArray[indexPath.row] + cell.titleLabel.text = modelItem.title + cell.bodyLabel.text = modelItem.body + + // Make sure the constraints have been added to this cell, since it may have just been created from scratch + cell.setNeedsUpdateConstraints() + cell.updateConstraintsIfNeeded() + + return cell + } + + // This will be the case for interface builder loaded cells (see viewDidLoad to switch approaches) + if let cell: NibTableViewCell = tableView.dequeueReusableCellWithIdentifier(kCellIdentifier) as? NibTableViewCell { + // Configure the cell for this indexPath + cell.updateFonts() + let modelItem = model.dataArray[indexPath.row] + cell.titleLabel.text = modelItem.title + cell.bodyLabel.text = modelItem.body + + // Make sure the constraints have been added to this cell, since it may have just been created from scratch + cell.setNeedsUpdateConstraints() + cell.updateConstraintsIfNeeded() + + return cell + } + + return nil } /* From 653f755ce3ebd01e229596fb0b3097cf6d7fc565 Mon Sep 17 00:00:00 2001 From: Tyler Fox Date: Tue, 24 Jun 2014 10:59:45 -0700 Subject: [PATCH 10/30] Replace UIView+AutoLayout with PureLayout --- .../project.pbxproj | 46 +- .../ALView+PureLayout.h} | 142 ++--- .../ALView+PureLayout.m} | 520 +++--------------- .../PureLayout/NSArray+PureLayout.h | 70 +++ .../PureLayout/NSArray+PureLayout.m | 358 ++++++++++++ .../NSLayoutConstraint+PureLayout.h | 45 ++ .../NSLayoutConstraint+PureLayout.m | 67 +++ .../PureLayout/PureLayout+Internal.h | 59 ++ .../PureLayout/PureLayout.h | 36 ++ .../PureLayout/PureLayoutDefines.h | 118 ++++ ...leViewCellWithAutoLayout-Bridging-Header.h | 2 +- 11 files changed, 907 insertions(+), 556 deletions(-) rename TableViewCellWithAutoLayout/{UIView+AutoLayout/UIView+AutoLayout.h => PureLayout/ALView+PureLayout.h} (62%) rename TableViewCellWithAutoLayout/{UIView+AutoLayout/UIView+AutoLayout.m => PureLayout/ALView+PureLayout.m} (67%) create mode 100755 TableViewCellWithAutoLayout/PureLayout/NSArray+PureLayout.h create mode 100755 TableViewCellWithAutoLayout/PureLayout/NSArray+PureLayout.m create mode 100755 TableViewCellWithAutoLayout/PureLayout/NSLayoutConstraint+PureLayout.h create mode 100755 TableViewCellWithAutoLayout/PureLayout/NSLayoutConstraint+PureLayout.m create mode 100644 TableViewCellWithAutoLayout/PureLayout/PureLayout+Internal.h create mode 100755 TableViewCellWithAutoLayout/PureLayout/PureLayout.h create mode 100755 TableViewCellWithAutoLayout/PureLayout/PureLayoutDefines.h diff --git a/TableViewCellWithAutoLayout.xcodeproj/project.pbxproj b/TableViewCellWithAutoLayout.xcodeproj/project.pbxproj index 56893a0..fee95aa 100644 --- a/TableViewCellWithAutoLayout.xcodeproj/project.pbxproj +++ b/TableViewCellWithAutoLayout.xcodeproj/project.pbxproj @@ -23,7 +23,9 @@ A7F5DDAA194408D9008E238B /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = A7F5DDA9194408D9008E238B /* AppDelegate.swift */; }; A7F5DDAC19440B7B008E238B /* Model.swift in Sources */ = {isa = PBXBuildFile; fileRef = A7F5DDAB19440B7B008E238B /* Model.swift */; }; A7F5DDAE194417DC008E238B /* TableViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = A7F5DDAD194417DC008E238B /* TableViewController.swift */; }; - B147F1841867A715002B0C25 /* UIView+AutoLayout.m in Sources */ = {isa = PBXBuildFile; fileRef = B147F1831867A715002B0C25 /* UIView+AutoLayout.m */; }; + B126BA121959EF4E0018DBAE /* ALView+PureLayout.m in Sources */ = {isa = PBXBuildFile; fileRef = B126BA0A1959EF4E0018DBAE /* ALView+PureLayout.m */; }; + B126BA131959EF4E0018DBAE /* NSArray+PureLayout.m in Sources */ = {isa = PBXBuildFile; fileRef = B126BA0C1959EF4E0018DBAE /* NSArray+PureLayout.m */; }; + B126BA141959EF4E0018DBAE /* NSLayoutConstraint+PureLayout.m in Sources */ = {isa = PBXBuildFile; fileRef = B126BA0E1959EF4E0018DBAE /* NSLayoutConstraint+PureLayout.m */; }; /* End PBXBuildFile section */ /* Begin PBXContainerItemProxy section */ @@ -57,8 +59,15 @@ A7F5DDA9194408D9008E238B /* AppDelegate.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = ""; }; A7F5DDAB19440B7B008E238B /* Model.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Model.swift; sourceTree = ""; }; A7F5DDAD194417DC008E238B /* TableViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TableViewController.swift; sourceTree = ""; }; - B147F1821867A715002B0C25 /* UIView+AutoLayout.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "UIView+AutoLayout.h"; sourceTree = ""; }; - B147F1831867A715002B0C25 /* UIView+AutoLayout.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "UIView+AutoLayout.m"; sourceTree = ""; }; + B126BA091959EF4E0018DBAE /* ALView+PureLayout.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "ALView+PureLayout.h"; sourceTree = ""; }; + B126BA0A1959EF4E0018DBAE /* ALView+PureLayout.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "ALView+PureLayout.m"; sourceTree = ""; }; + B126BA0B1959EF4E0018DBAE /* NSArray+PureLayout.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "NSArray+PureLayout.h"; sourceTree = ""; }; + B126BA0C1959EF4E0018DBAE /* NSArray+PureLayout.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "NSArray+PureLayout.m"; sourceTree = ""; }; + B126BA0D1959EF4E0018DBAE /* NSLayoutConstraint+PureLayout.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "NSLayoutConstraint+PureLayout.h"; sourceTree = ""; }; + B126BA0E1959EF4E0018DBAE /* NSLayoutConstraint+PureLayout.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "NSLayoutConstraint+PureLayout.m"; sourceTree = ""; }; + B126BA0F1959EF4E0018DBAE /* PureLayout+Internal.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "PureLayout+Internal.h"; sourceTree = ""; }; + B126BA101959EF4E0018DBAE /* PureLayout.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PureLayout.h; sourceTree = ""; }; + B126BA111959EF4E0018DBAE /* PureLayoutDefines.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PureLayoutDefines.h; sourceTree = ""; }; /* End PBXFileReference section */ /* Begin PBXFrameworksBuildPhase section */ @@ -118,7 +127,7 @@ 99BCDCAA18008C0000B8E66B /* TableViewCellWithAutoLayout */ = { isa = PBXGroup; children = ( - B147F1811867A715002B0C25 /* UIView+AutoLayout */, + B126BA081959EF4E0018DBAE /* PureLayout */, A7F5DDA9194408D9008E238B /* AppDelegate.swift */, 99BCDCB618008C0000B8E66B /* Images.xcassets */, 99BCDCD318008C1700B8E66B /* TableViewController */, @@ -167,6 +176,22 @@ path = TableViewController; sourceTree = ""; }; + B126BA081959EF4E0018DBAE /* PureLayout */ = { + isa = PBXGroup; + children = ( + B126BA091959EF4E0018DBAE /* ALView+PureLayout.h */, + B126BA0A1959EF4E0018DBAE /* ALView+PureLayout.m */, + B126BA0B1959EF4E0018DBAE /* NSArray+PureLayout.h */, + B126BA0C1959EF4E0018DBAE /* NSArray+PureLayout.m */, + B126BA0D1959EF4E0018DBAE /* NSLayoutConstraint+PureLayout.h */, + B126BA0E1959EF4E0018DBAE /* NSLayoutConstraint+PureLayout.m */, + B126BA0F1959EF4E0018DBAE /* PureLayout+Internal.h */, + B126BA101959EF4E0018DBAE /* PureLayout.h */, + B126BA111959EF4E0018DBAE /* PureLayoutDefines.h */, + ); + path = PureLayout; + sourceTree = ""; + }; B13F6E9E1947D6DE00FF3B42 /* Programmatic */ = { isa = PBXGroup; children = ( @@ -184,15 +209,6 @@ name = "Interface Builder"; sourceTree = ""; }; - B147F1811867A715002B0C25 /* UIView+AutoLayout */ = { - isa = PBXGroup; - children = ( - B147F1821867A715002B0C25 /* UIView+AutoLayout.h */, - B147F1831867A715002B0C25 /* UIView+AutoLayout.m */, - ); - path = "UIView+AutoLayout"; - sourceTree = ""; - }; /* End PBXGroup section */ /* Begin PBXNativeTarget section */ @@ -290,9 +306,11 @@ isa = PBXSourcesBuildPhase; buildActionMask = 2147483647; files = ( - B147F1841867A715002B0C25 /* UIView+AutoLayout.m in Sources */, 5A3B25361945F89500838EF4 /* NibTableViewCell.swift in Sources */, A7F5DDAE194417DC008E238B /* TableViewController.swift in Sources */, + B126BA121959EF4E0018DBAE /* ALView+PureLayout.m in Sources */, + B126BA131959EF4E0018DBAE /* NSArray+PureLayout.m in Sources */, + B126BA141959EF4E0018DBAE /* NSLayoutConstraint+PureLayout.m in Sources */, A7F5DDAA194408D9008E238B /* AppDelegate.swift in Sources */, A7F5DDAC19440B7B008E238B /* Model.swift in Sources */, A7C103221943F73D006A9720 /* TableViewCell.swift in Sources */, diff --git a/TableViewCellWithAutoLayout/UIView+AutoLayout/UIView+AutoLayout.h b/TableViewCellWithAutoLayout/PureLayout/ALView+PureLayout.h similarity index 62% rename from TableViewCellWithAutoLayout/UIView+AutoLayout/UIView+AutoLayout.h rename to TableViewCellWithAutoLayout/PureLayout/ALView+PureLayout.h index ea34ad7..9f7aef1 100755 --- a/TableViewCellWithAutoLayout/UIView+AutoLayout/UIView+AutoLayout.h +++ b/TableViewCellWithAutoLayout/PureLayout/ALView+PureLayout.h @@ -1,10 +1,10 @@ // -// UIView+AutoLayout.h -// v2.0.0 -// https://github.com/smileyborg/UIView-AutoLayout +// ALView+PureLayout.h +// v1.0.1 +// https://github.com/smileyborg/PureLayout // // Copyright (c) 2012 Richard Turton -// Copyright (c) 2013 Tyler Fox +// Copyright (c) 2013-2014 Tyler Fox // // This code is distributed under the terms and conditions of the MIT license. // @@ -27,39 +27,15 @@ // IN THE SOFTWARE. // -#import +#import "PureLayoutDefines.h" -#pragma mark ALAttributes -typedef NS_ENUM(NSInteger, ALEdge) { - ALEdgeLeft = NSLayoutAttributeLeft, // the left edge of the view - ALEdgeRight = NSLayoutAttributeRight, // the right edge of the view - ALEdgeTop = NSLayoutAttributeTop, // the top edge of the view - ALEdgeBottom = NSLayoutAttributeBottom, // the bottom edge of the view - ALEdgeLeading = NSLayoutAttributeLeading, // the leading edge of the view (left edge for left-to-right languages like English, right edge for right-to-left languages like Arabic) - ALEdgeTrailing = NSLayoutAttributeTrailing // the trailing edge of the view (right edge for left-to-right languages like English, left edge for right-to-left languages like Arabic) -}; - -typedef NS_ENUM(NSInteger, ALDimension) { - ALDimensionWidth = NSLayoutAttributeWidth, // the width of the view - ALDimensionHeight = NSLayoutAttributeHeight // the height of the view -}; - -typedef NS_ENUM(NSInteger, ALAxis) { - ALAxisVertical = NSLayoutAttributeCenterX, // a vertical line through the center of the view - ALAxisHorizontal = NSLayoutAttributeCenterY, // a horizontal line through the center of the view - ALAxisBaseline = NSLayoutAttributeBaseline // a horizontal line at the text baseline (not applicable to all views) -}; - -typedef void(^ALConstraintsBlock)(void); // a block of method calls to the UIView+AutoLayout category API - - -#pragma mark - UIView+AutoLayout +#pragma mark - ALView+PureLayout /** - A category on UIView that provides a simple yet powerful interface for creating Auto Layout constraints. + A category on UIView/NSView that provides a simple yet powerful interface for creating Auto Layout constraints. */ -@interface UIView (AutoLayout) +@interface ALView (PureLayout) #pragma mark Factory & Initializer Methods @@ -73,9 +49,9 @@ typedef void(^ALConstraintsBlock)(void); // a block of method calls to the UI #pragma mark Set Constraint Priority -/** Sets the constraint priority to the given value for all constraints created using the UIView+AutoLayout category API within the given constraints block. +/** Sets the constraint priority to the given value for all constraints created using the PureLayout API within the given constraints block. NOTE: This method will have no effect (and will NOT set the priority) on constraints created or added using the SDK directly within the block! */ -+ (void)autoSetPriority:(UILayoutPriority)priority forConstraints:(ALConstraintsBlock)block; ++ (void)autoSetPriority:(ALLayoutPriority)priority forConstraints:(ALConstraintsBlock)block; #pragma mark Remove Constraints @@ -125,49 +101,49 @@ typedef void(^ALConstraintsBlock)(void); // a block of method calls to the UI - (NSLayoutConstraint *)autoPinEdgeToSuperviewEdge:(ALEdge)edge withInset:(CGFloat)inset relation:(NSLayoutRelation)relation; /** Pins the edges of the view to the edges of its superview with the given edge insets. */ -- (NSArray *)autoPinEdgesToSuperviewEdgesWithInsets:(UIEdgeInsets)insets; +- (NSArray *)autoPinEdgesToSuperviewEdgesWithInsets:(ALEdgeInsets)insets; /** Pins 3 of the 4 edges of the view to the edges of its superview with the given edge insets, excluding one edge. */ -- (NSArray *)autoPinEdgesToSuperviewEdgesWithInsets:(UIEdgeInsets)insets excludingEdge:(ALEdge)edge; +- (NSArray *)autoPinEdgesToSuperviewEdgesWithInsets:(ALEdgeInsets)insets excludingEdge:(ALEdge)edge; #pragma mark Pin Edges /** Pins an edge of the view to a given edge of another view. */ -- (NSLayoutConstraint *)autoPinEdge:(ALEdge)edge toEdge:(ALEdge)toEdge ofView:(UIView *)peerView; +- (NSLayoutConstraint *)autoPinEdge:(ALEdge)edge toEdge:(ALEdge)toEdge ofView:(ALView *)peerView; /** Pins an edge of the view to a given edge of another view with an offset. */ -- (NSLayoutConstraint *)autoPinEdge:(ALEdge)edge toEdge:(ALEdge)toEdge ofView:(UIView *)peerView withOffset:(CGFloat)offset; +- (NSLayoutConstraint *)autoPinEdge:(ALEdge)edge toEdge:(ALEdge)toEdge ofView:(ALView *)peerView withOffset:(CGFloat)offset; /** Pins an edge of the view to a given edge of another view with an offset as a maximum or minimum. */ -- (NSLayoutConstraint *)autoPinEdge:(ALEdge)edge toEdge:(ALEdge)toEdge ofView:(UIView *)peerView withOffset:(CGFloat)offset relation:(NSLayoutRelation)relation; +- (NSLayoutConstraint *)autoPinEdge:(ALEdge)edge toEdge:(ALEdge)toEdge ofView:(ALView *)peerView withOffset:(CGFloat)offset relation:(NSLayoutRelation)relation; #pragma mark Align Axes /** Aligns an axis of the view to the same axis of another view. */ -- (NSLayoutConstraint *)autoAlignAxis:(ALAxis)axis toSameAxisOfView:(UIView *)peerView; +- (NSLayoutConstraint *)autoAlignAxis:(ALAxis)axis toSameAxisOfView:(ALView *)peerView; /** Aligns an axis of the view to the same axis of another view with an offset. */ -- (NSLayoutConstraint *)autoAlignAxis:(ALAxis)axis toSameAxisOfView:(UIView *)peerView withOffset:(CGFloat)offset; +- (NSLayoutConstraint *)autoAlignAxis:(ALAxis)axis toSameAxisOfView:(ALView *)peerView withOffset:(CGFloat)offset; #pragma mark Match Dimensions /** Matches a dimension of the view to a given dimension of another view. */ -- (NSLayoutConstraint *)autoMatchDimension:(ALDimension)dimension toDimension:(ALDimension)toDimension ofView:(UIView *)peerView; +- (NSLayoutConstraint *)autoMatchDimension:(ALDimension)dimension toDimension:(ALDimension)toDimension ofView:(ALView *)peerView; /** Matches a dimension of the view to a given dimension of another view with an offset. */ -- (NSLayoutConstraint *)autoMatchDimension:(ALDimension)dimension toDimension:(ALDimension)toDimension ofView:(UIView *)peerView withOffset:(CGFloat)offset; +- (NSLayoutConstraint *)autoMatchDimension:(ALDimension)dimension toDimension:(ALDimension)toDimension ofView:(ALView *)peerView withOffset:(CGFloat)offset; /** Matches a dimension of the view to a given dimension of another view with an offset as a maximum or minimum. */ -- (NSLayoutConstraint *)autoMatchDimension:(ALDimension)dimension toDimension:(ALDimension)toDimension ofView:(UIView *)peerView withOffset:(CGFloat)offset relation:(NSLayoutRelation)relation; +- (NSLayoutConstraint *)autoMatchDimension:(ALDimension)dimension toDimension:(ALDimension)toDimension ofView:(ALView *)peerView withOffset:(CGFloat)offset relation:(NSLayoutRelation)relation; /** Matches a dimension of the view to a multiple of a given dimension of another view. */ -- (NSLayoutConstraint *)autoMatchDimension:(ALDimension)dimension toDimension:(ALDimension)toDimension ofView:(UIView *)peerView withMultiplier:(CGFloat)multiplier; +- (NSLayoutConstraint *)autoMatchDimension:(ALDimension)dimension toDimension:(ALDimension)toDimension ofView:(ALView *)peerView withMultiplier:(CGFloat)multiplier; /** Matches a dimension of the view to a multiple of a given dimension of another view as a maximum or minimum. */ -- (NSLayoutConstraint *)autoMatchDimension:(ALDimension)dimension toDimension:(ALDimension)toDimension ofView:(UIView *)peerView withMultiplier:(CGFloat)multiplier relation:(NSLayoutRelation)relation; +- (NSLayoutConstraint *)autoMatchDimension:(ALDimension)dimension toDimension:(ALDimension)toDimension ofView:(ALView *)peerView withMultiplier:(CGFloat)multiplier relation:(NSLayoutRelation)relation; #pragma mark Set Dimensions @@ -185,33 +161,35 @@ typedef void(^ALConstraintsBlock)(void); // a block of method calls to the UI #pragma mark Set Content Compression Resistance & Hugging /** Sets the priority of content compression resistance for an axis. - NOTE: This method must only be called from within the block passed into the method +[UIView autoSetPriority:forConstraints:] */ + NOTE: This method must only be called from within the block passed into the method +[autoSetPriority:forConstraints:] */ - (void)autoSetContentCompressionResistancePriorityForAxis:(ALAxis)axis; /** Sets the priority of content hugging for an axis. - NOTE: This method must only be called from within the block passed into the method +[UIView autoSetPriority:forConstraints:] */ + NOTE: This method must only be called from within the block passed into the method +[autoSetPriority:forConstraints:] */ - (void)autoSetContentHuggingPriorityForAxis:(ALAxis)axis; #pragma mark Constrain Any Attributes /** Constrains an attribute (any ALEdge, ALAxis, or ALDimension) of the view to a given attribute of another view. */ -- (NSLayoutConstraint *)autoConstrainAttribute:(NSInteger)attribute toAttribute:(NSInteger)toAttribute ofView:(UIView *)peerView; +- (NSLayoutConstraint *)autoConstrainAttribute:(NSInteger)attribute toAttribute:(NSInteger)toAttribute ofView:(ALView *)peerView; /** Constrains an attribute (any ALEdge, ALAxis, or ALDimension) of the view to a given attribute of another view with an offset. */ -- (NSLayoutConstraint *)autoConstrainAttribute:(NSInteger)attribute toAttribute:(NSInteger)toAttribute ofView:(UIView *)peerView withOffset:(CGFloat)offset; +- (NSLayoutConstraint *)autoConstrainAttribute:(NSInteger)attribute toAttribute:(NSInteger)toAttribute ofView:(ALView *)peerView withOffset:(CGFloat)offset; /** Constrains an attribute (any ALEdge, ALAxis, or ALDimension) of the view to a given attribute of another view with an offset as a maximum or minimum. */ -- (NSLayoutConstraint *)autoConstrainAttribute:(NSInteger)attribute toAttribute:(NSInteger)toAttribute ofView:(UIView *)peerView withOffset:(CGFloat)offset relation:(NSLayoutRelation)relation; +- (NSLayoutConstraint *)autoConstrainAttribute:(NSInteger)attribute toAttribute:(NSInteger)toAttribute ofView:(ALView *)peerView withOffset:(CGFloat)offset relation:(NSLayoutRelation)relation; /** Constrains an attribute (any ALEdge, ALAxis, or ALDimension) of the view to a given attribute of another view with a multiplier. */ -- (NSLayoutConstraint *)autoConstrainAttribute:(NSInteger)attribute toAttribute:(NSInteger)toAttribute ofView:(UIView *)peerView withMultiplier:(CGFloat)multiplier; +- (NSLayoutConstraint *)autoConstrainAttribute:(NSInteger)attribute toAttribute:(NSInteger)toAttribute ofView:(ALView *)peerView withMultiplier:(CGFloat)multiplier; /** Constrains an attribute (any ALEdge, ALAxis, or ALDimension) of the view to a given attribute of another view with a multiplier as a maximum or minimum. */ -- (NSLayoutConstraint *)autoConstrainAttribute:(NSInteger)attribute toAttribute:(NSInteger)toAttribute ofView:(UIView *)peerView withMultiplier:(CGFloat)multiplier relation:(NSLayoutRelation)relation; +- (NSLayoutConstraint *)autoConstrainAttribute:(NSInteger)attribute toAttribute:(NSInteger)toAttribute ofView:(ALView *)peerView withMultiplier:(CGFloat)multiplier relation:(NSLayoutRelation)relation; -#pragma mark Pin to Layout Guides +#pragma mark Pin to Layout Guides (iOS only) + +#if TARGET_OS_IPHONE /** Pins the top edge of the view to the top layout guide of the given view controller with an inset. */ - (NSLayoutConstraint *)autoPinToTopLayoutGuideOfViewController:(UIViewController *)viewController withInset:(CGFloat)inset; @@ -219,60 +197,6 @@ typedef void(^ALConstraintsBlock)(void); // a block of method calls to the UI /** Pins the bottom edge of the view to the bottom layout guide of the given view controller with an inset. */ - (NSLayoutConstraint *)autoPinToBottomLayoutGuideOfViewController:(UIViewController *)viewController withInset:(CGFloat)inset; -@end - - -#pragma mark - NSArray+AutoLayout - -/** - A category on NSArray that provides a simple yet powerful interface for applying constraints to groups of views. - */ -@interface NSArray (AutoLayout) - - -#pragma mark Constrain Multiple Views - -/** Aligns views in this array to one another along a given edge. */ -- (NSArray *)autoAlignViewsToEdge:(ALEdge)edge; - -/** Aligns views in this array to one another along a given axis. */ -- (NSArray *)autoAlignViewsToAxis:(ALAxis)axis; - -/** Matches a given dimension of all the views in this array. */ -- (NSArray *)autoMatchViewsDimension:(ALDimension)dimension; - -/** Sets the given dimension of all the views in this array to a given size. */ -- (NSArray *)autoSetViewsDimension:(ALDimension)dimension toSize:(CGFloat)size; - - -#pragma mark Distribute Multiple Views - -/** Distributes the views in this array equally along the selected axis in their superview. Views will be the same size (variable) in the dimension along the axis and will have spacing (fixed) between them. */ -- (NSArray *)autoDistributeViewsAlongAxis:(ALAxis)axis withFixedSpacing:(CGFloat)spacing alignment:(NSLayoutFormatOptions)alignment; - -/** Distributes the views in this array equally along the selected axis in their superview. Views will be the same size (variable) in the dimension along the axis and will have spacing (fixed) between them, with optional insets from the first and last views to their superview. */ -- (NSArray *)autoDistributeViewsAlongAxis:(ALAxis)axis withFixedSpacing:(CGFloat)spacing insetSpacing:(BOOL)shouldSpaceInsets alignment:(NSLayoutFormatOptions)alignment; - -/** Distributes the views in this array equally along the selected axis in their superview. Views will be the same size (fixed) in the dimension along the axis and will have spacing (variable) between them. */ -- (NSArray *)autoDistributeViewsAlongAxis:(ALAxis)axis withFixedSize:(CGFloat)size alignment:(NSLayoutFormatOptions)alignment; - -/** Distributes the views in this array equally along the selected axis in their superview. Views will be the same size (fixed) in the dimension along the axis and will have spacing (variable) between them, with optional insets from the first and last views to their superview. */ -- (NSArray *)autoDistributeViewsAlongAxis:(ALAxis)axis withFixedSize:(CGFloat)size insetSpacing:(BOOL)shouldSpaceInsets alignment:(NSLayoutFormatOptions)alignment; - -@end - - -#pragma mark - NSLayoutConstraint+AutoLayout - -/** - A category on NSLayoutConstraint that allows constraints to be easily removed. - */ -@interface NSLayoutConstraint (AutoLayout) - -/** Adds the constraint to the appropriate view. */ -- (void)autoInstall; - -/** Removes the constraint from the view it has been added to. */ -- (void)autoRemove; +#endif /* TARGET_OS_IPHONE */ @end diff --git a/TableViewCellWithAutoLayout/UIView+AutoLayout/UIView+AutoLayout.m b/TableViewCellWithAutoLayout/PureLayout/ALView+PureLayout.m similarity index 67% rename from TableViewCellWithAutoLayout/UIView+AutoLayout/UIView+AutoLayout.m rename to TableViewCellWithAutoLayout/PureLayout/ALView+PureLayout.m index d529a38..0376801 100755 --- a/TableViewCellWithAutoLayout/UIView+AutoLayout/UIView+AutoLayout.m +++ b/TableViewCellWithAutoLayout/PureLayout/ALView+PureLayout.m @@ -1,10 +1,10 @@ // -// UIView+AutoLayout.m -// v2.0.0 -// https://github.com/smileyborg/UIView-AutoLayout +// ALView+PureLayout.m +// v1.0.1 +// https://github.com/smileyborg/PureLayout // // Copyright (c) 2012 Richard Turton -// Copyright (c) 2013 Tyler Fox +// Copyright (c) 2013-2014 Tyler Fox // // This code is distributed under the terms and conditions of the MIT license. // @@ -27,12 +27,13 @@ // IN THE SOFTWARE. // -#import "UIView+AutoLayout.h" +#import "ALView+PureLayout.h" +#import "NSLayoutConstraint+PureLayout.h" -#pragma mark - UIView+AutoLayout +#pragma mark - ALView+PureLayout -@implementation UIView (AutoLayout) +@implementation ALView (PureLayout) #pragma mark Factory & Initializer Methods @@ -42,7 +43,7 @@ @implementation UIView (AutoLayout) */ + (instancetype)newAutoLayoutView { - UIView *view = [self new]; + ALView *view = [self new]; view.translatesAutoresizingMaskIntoConstraints = NO; return view; } @@ -65,32 +66,30 @@ - (instancetype)initForAutoLayout /** A global variable that determines the priority of all constraints created and added by this category. Defaults to Required, will only be a different value while executing a constraints block passed into the - +[UIView autoSetPriority:forConstraints:] method (as that method will reset the value back to Required + +[autoSetPriority:forConstraints:] method (as that method will reset the value back to Required before returning). - NOTE: As UIKit is not thread safe, access to this variable is not synchronized (and should only be done - on the main thread). + NOTE: Access to this variable is not synchronized (and should only be done on the main thread). */ -static UILayoutPriority _al_globalConstraintPriority = UILayoutPriorityRequired; +static ALLayoutPriority _al_globalConstraintPriority = ALLayoutPriorityRequired; /** A global variable that is set to YES while the constraints block passed in to the - +[UIView autoSetPriority:forConstraints:] method is executing. - NOTE: As UIKit is not thread safe, access to this variable is not synchronized (and should only be done - on the main thread). + +[autoSetPriority:forConstraints:] method is executing. + NOTE: Access to this variable is not synchronized (and should only be done on the main thread). */ static BOOL _al_isExecutingConstraintsBlock = NO; /** - Sets the constraint priority to the given value for all constraints created using the UIView+AutoLayout - category API within the given constraints block. + Sets the constraint priority to the given value for all constraints created using the PureLayout + API within the given constraints block. NOTE: This method will have no effect (and will NOT set the priority) on constraints created or added using the SDK directly within the block! @param priority The layout priority to be set on all constraints in the constraints block. - @param block A block of method calls to the UIView+AutoLayout API that create and add constraints. + @param block A block of method calls to the PureLayout API that create and add constraints. */ -+ (void)autoSetPriority:(UILayoutPriority)priority forConstraints:(ALConstraintsBlock)block ++ (void)autoSetPriority:(ALLayoutPriority)priority forConstraints:(ALConstraintsBlock)block { NSAssert(block, @"The constraints block cannot be nil."); if (block) { @@ -98,7 +97,7 @@ + (void)autoSetPriority:(UILayoutPriority)priority forConstraints:(ALConstraints _al_isExecutingConstraintsBlock = YES; block(); _al_isExecutingConstraintsBlock = NO; - _al_globalConstraintPriority = UILayoutPriorityRequired; + _al_globalConstraintPriority = ALLayoutPriorityRequired; } } @@ -113,7 +112,7 @@ + (void)autoSetPriority:(UILayoutPriority)priority forConstraints:(ALConstraints + (void)autoRemoveConstraint:(NSLayoutConstraint *)constraint { if (constraint.secondItem) { - UIView *commonSuperview = [constraint.firstItem al_commonSuperviewWithView:constraint.secondItem]; + ALView *commonSuperview = [constraint.firstItem al_commonSuperviewWithView:constraint.secondItem]; while (commonSuperview) { if ([commonSuperview.constraints containsObject:constraint]) { [commonSuperview removeConstraint:constraint]; @@ -168,7 +167,7 @@ - (void)autoRemoveConstraintsAffectingView - (void)autoRemoveConstraintsAffectingViewIncludingImplicitConstraints:(BOOL)shouldRemoveImplicitConstraints { NSMutableArray *constraintsToRemove = [NSMutableArray new]; - UIView *startView = self; + ALView *startView = self; do { for (NSLayoutConstraint *constraint in startView.constraints) { BOOL isImplicitConstraint = [NSStringFromClass([constraint class]) isEqualToString:@"NSContentSizeLayoutConstraint"]; @@ -180,7 +179,7 @@ - (void)autoRemoveConstraintsAffectingViewIncludingImplicitConstraints:(BOOL)sho } startView = startView.superview; } while (startView); - [UIView autoRemoveConstraints:constraintsToRemove]; + [ALView autoRemoveConstraints:constraintsToRemove]; } /** @@ -206,7 +205,7 @@ - (void)autoRemoveConstraintsAffectingViewAndSubviews - (void)autoRemoveConstraintsAffectingViewAndSubviewsIncludingImplicitConstraints:(BOOL)shouldRemoveImplicitConstraints { [self autoRemoveConstraintsAffectingViewIncludingImplicitConstraints:shouldRemoveImplicitConstraints]; - for (UIView *subview in self.subviews) { + for (ALView *subview in self.subviews) { [subview autoRemoveConstraintsAffectingViewAndSubviewsIncludingImplicitConstraints:shouldRemoveImplicitConstraints]; } } @@ -236,9 +235,9 @@ - (NSArray *)autoCenterInSuperview - (NSLayoutConstraint *)autoAlignAxisToSuperviewAxis:(ALAxis)axis { self.translatesAutoresizingMaskIntoConstraints = NO; - UIView *superview = self.superview; + ALView *superview = self.superview; NSAssert(superview, @"View's superview must not be nil.\nView: %@", self); - NSLayoutAttribute attribute = [UIView al_attributeForAxis:axis]; + NSLayoutAttribute attribute = [ALView al_attributeForAxis:axis]; NSLayoutConstraint *constraint = [NSLayoutConstraint constraintWithItem:self attribute:attribute relatedBy:NSLayoutRelationEqual toItem:superview attribute:attribute multiplier:1.0f constant:0.0f]; [constraint autoInstall]; return constraint; @@ -270,7 +269,7 @@ - (NSLayoutConstraint *)autoPinEdgeToSuperviewEdge:(ALEdge)edge withInset:(CGFlo - (NSLayoutConstraint *)autoPinEdgeToSuperviewEdge:(ALEdge)edge withInset:(CGFloat)inset relation:(NSLayoutRelation)relation { self.translatesAutoresizingMaskIntoConstraints = NO; - UIView *superview = self.superview; + ALView *superview = self.superview; NSAssert(superview, @"View's superview must not be nil.\nView: %@", self); if (edge == ALEdgeBottom || edge == ALEdgeRight || edge == ALEdgeTrailing) { // The bottom, right, and trailing insets (and relations, if an inequality) are inverted to become offsets @@ -291,7 +290,7 @@ - (NSLayoutConstraint *)autoPinEdgeToSuperviewEdge:(ALEdge)edge withInset:(CGFlo @param insets The insets for this view's edges from the superview's edges. @return An array of constraints added. */ -- (NSArray *)autoPinEdgesToSuperviewEdgesWithInsets:(UIEdgeInsets)insets +- (NSArray *)autoPinEdgesToSuperviewEdgesWithInsets:(ALEdgeInsets)insets { NSMutableArray *constraints = [NSMutableArray new]; [constraints addObject:[self autoPinEdgeToSuperviewEdge:ALEdgeTop withInset:insets.top]]; @@ -310,7 +309,7 @@ - (NSArray *)autoPinEdgesToSuperviewEdgesWithInsets:(UIEdgeInsets)insets @param edge The edge of this view to exclude in pinning to the superview; this method will not apply any constraint to it. @return An array of constraints added. */ -- (NSArray *)autoPinEdgesToSuperviewEdgesWithInsets:(UIEdgeInsets)insets excludingEdge:(ALEdge)edge +- (NSArray *)autoPinEdgesToSuperviewEdgesWithInsets:(ALEdgeInsets)insets excludingEdge:(ALEdge)edge { NSMutableArray *constraints = [NSMutableArray new]; if (edge != ALEdgeTop) { @@ -339,7 +338,7 @@ - (NSArray *)autoPinEdgesToSuperviewEdgesWithInsets:(UIEdgeInsets)insets excludi @param peerView The peer view to pin to. Must be in the same view hierarchy as this view. @return The constraint added. */ -- (NSLayoutConstraint *)autoPinEdge:(ALEdge)edge toEdge:(ALEdge)toEdge ofView:(UIView *)peerView +- (NSLayoutConstraint *)autoPinEdge:(ALEdge)edge toEdge:(ALEdge)toEdge ofView:(ALView *)peerView { return [self autoPinEdge:edge toEdge:toEdge ofView:peerView withOffset:0.0f]; } @@ -353,7 +352,7 @@ - (NSLayoutConstraint *)autoPinEdge:(ALEdge)edge toEdge:(ALEdge)toEdge ofView:(U @param offset The offset between the edge of this view and the edge of the peer view. @return The constraint added. */ -- (NSLayoutConstraint *)autoPinEdge:(ALEdge)edge toEdge:(ALEdge)toEdge ofView:(UIView *)peerView withOffset:(CGFloat)offset +- (NSLayoutConstraint *)autoPinEdge:(ALEdge)edge toEdge:(ALEdge)toEdge ofView:(ALView *)peerView withOffset:(CGFloat)offset { return [self autoPinEdge:edge toEdge:toEdge ofView:peerView withOffset:offset relation:NSLayoutRelationEqual]; } @@ -368,11 +367,11 @@ - (NSLayoutConstraint *)autoPinEdge:(ALEdge)edge toEdge:(ALEdge)toEdge ofView:(U @param relation Whether the offset should be at least, at most, or exactly equal to the given value. @return The constraint added. */ -- (NSLayoutConstraint *)autoPinEdge:(ALEdge)edge toEdge:(ALEdge)toEdge ofView:(UIView *)peerView withOffset:(CGFloat)offset relation:(NSLayoutRelation)relation +- (NSLayoutConstraint *)autoPinEdge:(ALEdge)edge toEdge:(ALEdge)toEdge ofView:(ALView *)peerView withOffset:(CGFloat)offset relation:(NSLayoutRelation)relation { self.translatesAutoresizingMaskIntoConstraints = NO; - NSLayoutAttribute attribute = [UIView al_attributeForEdge:edge]; - NSLayoutAttribute toAttribute = [UIView al_attributeForEdge:toEdge]; + NSLayoutAttribute attribute = [ALView al_attributeForEdge:edge]; + NSLayoutAttribute toAttribute = [ALView al_attributeForEdge:toEdge]; NSLayoutConstraint *constraint = [NSLayoutConstraint constraintWithItem:self attribute:attribute relatedBy:relation toItem:peerView attribute:toAttribute multiplier:1.0f constant:offset]; [constraint autoInstall]; return constraint; @@ -388,7 +387,7 @@ - (NSLayoutConstraint *)autoPinEdge:(ALEdge)edge toEdge:(ALEdge)toEdge ofView:(U @param peerView The peer view to align to. Must be in the same view hierarchy as this view. @return The constraint added. */ -- (NSLayoutConstraint *)autoAlignAxis:(ALAxis)axis toSameAxisOfView:(UIView *)peerView +- (NSLayoutConstraint *)autoAlignAxis:(ALAxis)axis toSameAxisOfView:(ALView *)peerView { return [self autoAlignAxis:axis toSameAxisOfView:peerView withOffset:0.0f]; } @@ -401,10 +400,10 @@ - (NSLayoutConstraint *)autoAlignAxis:(ALAxis)axis toSameAxisOfView:(UIView *)pe @param offset The offset between the axis of this view and the axis of the peer view. @return The constraint added. */ -- (NSLayoutConstraint *)autoAlignAxis:(ALAxis)axis toSameAxisOfView:(UIView *)peerView withOffset:(CGFloat)offset +- (NSLayoutConstraint *)autoAlignAxis:(ALAxis)axis toSameAxisOfView:(ALView *)peerView withOffset:(CGFloat)offset { self.translatesAutoresizingMaskIntoConstraints = NO; - NSLayoutAttribute attribute = [UIView al_attributeForAxis:axis]; + NSLayoutAttribute attribute = [ALView al_attributeForAxis:axis]; NSLayoutConstraint *constraint = [NSLayoutConstraint constraintWithItem:self attribute:attribute relatedBy:NSLayoutRelationEqual toItem:peerView attribute:attribute multiplier:1.0f constant:offset]; [constraint autoInstall]; return constraint; @@ -421,7 +420,7 @@ - (NSLayoutConstraint *)autoAlignAxis:(ALAxis)axis toSameAxisOfView:(UIView *)pe @param peerView The peer view to match to. Must be in the same view hierarchy as this view. @return The constraint added. */ -- (NSLayoutConstraint *)autoMatchDimension:(ALDimension)dimension toDimension:(ALDimension)toDimension ofView:(UIView *)peerView +- (NSLayoutConstraint *)autoMatchDimension:(ALDimension)dimension toDimension:(ALDimension)toDimension ofView:(ALView *)peerView { return [self autoMatchDimension:dimension toDimension:toDimension ofView:peerView withOffset:0.0f]; } @@ -435,7 +434,7 @@ - (NSLayoutConstraint *)autoMatchDimension:(ALDimension)dimension toDimension:(A @param offset The offset between the dimension of this view and the dimension of the peer view. @return The constraint added. */ -- (NSLayoutConstraint *)autoMatchDimension:(ALDimension)dimension toDimension:(ALDimension)toDimension ofView:(UIView *)peerView withOffset:(CGFloat)offset +- (NSLayoutConstraint *)autoMatchDimension:(ALDimension)dimension toDimension:(ALDimension)toDimension ofView:(ALView *)peerView withOffset:(CGFloat)offset { return [self autoMatchDimension:dimension toDimension:toDimension ofView:peerView withOffset:offset relation:NSLayoutRelationEqual]; } @@ -450,11 +449,11 @@ - (NSLayoutConstraint *)autoMatchDimension:(ALDimension)dimension toDimension:(A @param relation Whether the offset should be at least, at most, or exactly equal to the given value. @return The constraint added. */ -- (NSLayoutConstraint *)autoMatchDimension:(ALDimension)dimension toDimension:(ALDimension)toDimension ofView:(UIView *)peerView withOffset:(CGFloat)offset relation:(NSLayoutRelation)relation +- (NSLayoutConstraint *)autoMatchDimension:(ALDimension)dimension toDimension:(ALDimension)toDimension ofView:(ALView *)peerView withOffset:(CGFloat)offset relation:(NSLayoutRelation)relation { self.translatesAutoresizingMaskIntoConstraints = NO; - NSLayoutAttribute attribute = [UIView al_attributeForDimension:dimension]; - NSLayoutAttribute toAttribute = [UIView al_attributeForDimension:toDimension]; + NSLayoutAttribute attribute = [ALView al_attributeForDimension:dimension]; + NSLayoutAttribute toAttribute = [ALView al_attributeForDimension:toDimension]; NSLayoutConstraint *constraint = [NSLayoutConstraint constraintWithItem:self attribute:attribute relatedBy:relation toItem:peerView attribute:toAttribute multiplier:1.0f constant:offset]; [constraint autoInstall]; return constraint; @@ -469,7 +468,7 @@ - (NSLayoutConstraint *)autoMatchDimension:(ALDimension)dimension toDimension:(A @param multiplier The multiple of the peer view's given dimension that this view's given dimension should be. @return The constraint added. */ -- (NSLayoutConstraint *)autoMatchDimension:(ALDimension)dimension toDimension:(ALDimension)toDimension ofView:(UIView *)peerView withMultiplier:(CGFloat)multiplier +- (NSLayoutConstraint *)autoMatchDimension:(ALDimension)dimension toDimension:(ALDimension)toDimension ofView:(ALView *)peerView withMultiplier:(CGFloat)multiplier { return [self autoMatchDimension:dimension toDimension:toDimension ofView:peerView withMultiplier:multiplier relation:NSLayoutRelationEqual]; } @@ -484,11 +483,11 @@ - (NSLayoutConstraint *)autoMatchDimension:(ALDimension)dimension toDimension:(A @param relation Whether the multiple should be at least, at most, or exactly equal to the given value. @return The constraint added. */ -- (NSLayoutConstraint *)autoMatchDimension:(ALDimension)dimension toDimension:(ALDimension)toDimension ofView:(UIView *)peerView withMultiplier:(CGFloat)multiplier relation:(NSLayoutRelation)relation +- (NSLayoutConstraint *)autoMatchDimension:(ALDimension)dimension toDimension:(ALDimension)toDimension ofView:(ALView *)peerView withMultiplier:(CGFloat)multiplier relation:(NSLayoutRelation)relation { self.translatesAutoresizingMaskIntoConstraints = NO; - NSLayoutAttribute attribute = [UIView al_attributeForDimension:dimension]; - NSLayoutAttribute toAttribute = [UIView al_attributeForDimension:toDimension]; + NSLayoutAttribute attribute = [ALView al_attributeForDimension:dimension]; + NSLayoutAttribute toAttribute = [ALView al_attributeForDimension:toDimension]; NSLayoutConstraint *constraint = [NSLayoutConstraint constraintWithItem:self attribute:attribute relatedBy:relation toItem:peerView attribute:toAttribute multiplier:multiplier constant:0.0f]; [constraint autoInstall]; return constraint; @@ -534,7 +533,7 @@ - (NSLayoutConstraint *)autoSetDimension:(ALDimension)dimension toSize:(CGFloat) - (NSLayoutConstraint *)autoSetDimension:(ALDimension)dimension toSize:(CGFloat)size relation:(NSLayoutRelation)relation { self.translatesAutoresizingMaskIntoConstraints = NO; - NSLayoutAttribute attribute = [UIView al_attributeForDimension:dimension]; + NSLayoutAttribute attribute = [ALView al_attributeForDimension:dimension]; NSLayoutConstraint *constraint = [NSLayoutConstraint constraintWithItem:self attribute:attribute relatedBy:relation toItem:nil attribute:NSLayoutAttributeNotAnAttribute multiplier:0.0f constant:size]; [constraint autoInstall]; return constraint; @@ -545,33 +544,41 @@ - (NSLayoutConstraint *)autoSetDimension:(ALDimension)dimension toSize:(CGFloat) /** Sets the priority of content compression resistance for an axis. - NOTE: This method must only be called from within the block passed into the method +[UIView autoSetPriority:forConstraints:] + NOTE: This method must only be called from within the block passed into the method +[autoSetPriority:forConstraints:] @param axis The axis to set the content compression resistance priority for. */ - (void)autoSetContentCompressionResistancePriorityForAxis:(ALAxis)axis { - NSAssert(_al_isExecutingConstraintsBlock, @"%@ should only be called from within the block passed into the method +[UIView autoSetPriority:forConstraints:]", NSStringFromSelector(_cmd)); + NSAssert(_al_isExecutingConstraintsBlock, @"%@ should only be called from within the block passed into the method +[autoSetPriority:forConstraints:]", NSStringFromSelector(_cmd)); if (_al_isExecutingConstraintsBlock) { self.translatesAutoresizingMaskIntoConstraints = NO; - UILayoutConstraintAxis constraintAxis = [UIView al_constraintAxisForAxis:axis]; + ALLayoutConstraintAxis constraintAxis = [ALView al_constraintAxisForAxis:axis]; +#if TARGET_OS_IPHONE [self setContentCompressionResistancePriority:_al_globalConstraintPriority forAxis:constraintAxis]; +#else + [self setContentCompressionResistancePriority:_al_globalConstraintPriority forOrientation:constraintAxis]; +#endif /* TARGET_OS_IPHONE */ } } /** Sets the priority of content hugging for an axis. - NOTE: This method must only be called from within the block passed into the method +[UIView autoSetPriority:forConstraints:] + NOTE: This method must only be called from within the block passed into the method +[autoSetPriority:forConstraints:] @param axis The axis to set the content hugging priority for. */ - (void)autoSetContentHuggingPriorityForAxis:(ALAxis)axis { - NSAssert(_al_isExecutingConstraintsBlock, @"%@ should only be called from within the block passed into the method +[UIView autoSetPriority:forConstraints:]", NSStringFromSelector(_cmd)); + NSAssert(_al_isExecutingConstraintsBlock, @"%@ should only be called from within the block passed into the method +[autoSetPriority:forConstraints:]", NSStringFromSelector(_cmd)); if (_al_isExecutingConstraintsBlock) { self.translatesAutoresizingMaskIntoConstraints = NO; - UILayoutConstraintAxis constraintAxis = [UIView al_constraintAxisForAxis:axis]; + ALLayoutConstraintAxis constraintAxis = [ALView al_constraintAxisForAxis:axis]; +#if TARGET_OS_IPHONE [self setContentHuggingPriority:_al_globalConstraintPriority forAxis:constraintAxis]; +#else + [self setContentHuggingPriority:_al_globalConstraintPriority forOrientation:constraintAxis]; +#endif /* TARGET_OS_IPHONE */ } } @@ -587,7 +594,7 @@ Constrains an attribute (any ALEdge, ALAxis, or ALDimension) of the view to a gi @param peerView The peer view to constrain to. Must be in the same view hierarchy as this view. @return The constraint added. */ -- (NSLayoutConstraint *)autoConstrainAttribute:(NSInteger)ALAttribute toAttribute:(NSInteger)toALAttribute ofView:(UIView *)peerView +- (NSLayoutConstraint *)autoConstrainAttribute:(NSInteger)ALAttribute toAttribute:(NSInteger)toALAttribute ofView:(ALView *)peerView { return [self autoConstrainAttribute:ALAttribute toAttribute:toALAttribute ofView:peerView withOffset:0.0f]; } @@ -602,7 +609,7 @@ Constrains an attribute (any ALEdge, ALAxis, or ALDimension) of the view to a gi @param offset The offset between the attribute of this view and the attribute of the peer view. @return The constraint added. */ -- (NSLayoutConstraint *)autoConstrainAttribute:(NSInteger)ALAttribute toAttribute:(NSInteger)toALAttribute ofView:(UIView *)peerView withOffset:(CGFloat)offset +- (NSLayoutConstraint *)autoConstrainAttribute:(NSInteger)ALAttribute toAttribute:(NSInteger)toALAttribute ofView:(ALView *)peerView withOffset:(CGFloat)offset { return [self autoConstrainAttribute:ALAttribute toAttribute:toALAttribute ofView:peerView withOffset:offset relation:NSLayoutRelationEqual]; } @@ -618,11 +625,11 @@ Constrains an attribute (any ALEdge, ALAxis, or ALDimension) of the view to a gi @param relation Whether the offset should be at least, at most, or exactly equal to the given value. @return The constraint added. */ -- (NSLayoutConstraint *)autoConstrainAttribute:(NSInteger)ALAttribute toAttribute:(NSInteger)toALAttribute ofView:(UIView *)peerView withOffset:(CGFloat)offset relation:(NSLayoutRelation)relation +- (NSLayoutConstraint *)autoConstrainAttribute:(NSInteger)ALAttribute toAttribute:(NSInteger)toALAttribute ofView:(ALView *)peerView withOffset:(CGFloat)offset relation:(NSLayoutRelation)relation { self.translatesAutoresizingMaskIntoConstraints = NO; - NSLayoutAttribute attribute = [UIView al_attributeForALAttribute:ALAttribute]; - NSLayoutAttribute toAttribute = [UIView al_attributeForALAttribute:toALAttribute]; + NSLayoutAttribute attribute = [ALView al_attributeForALAttribute:ALAttribute]; + NSLayoutAttribute toAttribute = [ALView al_attributeForALAttribute:toALAttribute]; NSLayoutConstraint *constraint = [NSLayoutConstraint constraintWithItem:self attribute:attribute relatedBy:relation toItem:peerView attribute:toAttribute multiplier:1.0f constant:offset]; [constraint autoInstall]; return constraint; @@ -638,7 +645,7 @@ Constrains an attribute (any ALEdge, ALAxis, or ALDimension) of the view to a gi @param multiplier The multiplier between the attribute of this view and the attribute of the peer view. @return The constraint added. */ -- (NSLayoutConstraint *)autoConstrainAttribute:(NSInteger)ALAttribute toAttribute:(NSInteger)toALAttribute ofView:(UIView *)peerView withMultiplier:(CGFloat)multiplier +- (NSLayoutConstraint *)autoConstrainAttribute:(NSInteger)ALAttribute toAttribute:(NSInteger)toALAttribute ofView:(ALView *)peerView withMultiplier:(CGFloat)multiplier { return [self autoConstrainAttribute:ALAttribute toAttribute:toALAttribute ofView:peerView withMultiplier:multiplier relation:NSLayoutRelationEqual]; } @@ -654,11 +661,11 @@ Constrains an attribute (any ALEdge, ALAxis, or ALDimension) of the view to a gi @param relation Whether the multiplier should be at least, at most, or exactly equal to the given value. @return The constraint added. */ -- (NSLayoutConstraint *)autoConstrainAttribute:(NSInteger)ALAttribute toAttribute:(NSInteger)toALAttribute ofView:(UIView *)peerView withMultiplier:(CGFloat)multiplier relation:(NSLayoutRelation)relation +- (NSLayoutConstraint *)autoConstrainAttribute:(NSInteger)ALAttribute toAttribute:(NSInteger)toALAttribute ofView:(ALView *)peerView withMultiplier:(CGFloat)multiplier relation:(NSLayoutRelation)relation { self.translatesAutoresizingMaskIntoConstraints = NO; - NSLayoutAttribute attribute = [UIView al_attributeForALAttribute:ALAttribute]; - NSLayoutAttribute toAttribute = [UIView al_attributeForALAttribute:toALAttribute]; + NSLayoutAttribute attribute = [ALView al_attributeForALAttribute:ALAttribute]; + NSLayoutAttribute toAttribute = [ALView al_attributeForALAttribute:toALAttribute]; NSLayoutConstraint *constraint = [NSLayoutConstraint constraintWithItem:self attribute:attribute relatedBy:relation toItem:peerView attribute:toAttribute multiplier:multiplier constant:0.0f]; [constraint autoInstall]; return constraint; @@ -667,6 +674,8 @@ - (NSLayoutConstraint *)autoConstrainAttribute:(NSInteger)ALAttribute toAttribut #pragma mark Pin to Layout Guides +#if TARGET_OS_IPHONE + /** Pins the top edge of the view to the top layout guide of the given view controller with an inset. For compatibility with iOS 6 (where layout guides do not exist), this method will simply pin the top edge of @@ -709,6 +718,8 @@ - (NSLayoutConstraint *)autoPinToBottomLayoutGuideOfViewController:(UIViewContro } } +#endif /* TARGET_OS_IPHONE */ + #pragma mark Internal Helper Methods @@ -857,20 +868,20 @@ + (NSLayoutAttribute)al_attributeForALAttribute:(NSInteger)ALAttribute } /** - Returns the corresponding UILayoutConstraintAxis for the given ALAxis. + Returns the corresponding ALLayoutConstraintAxis for the given ALAxis. @return The constraint axis for the given axis. */ -+ (UILayoutConstraintAxis)al_constraintAxisForAxis:(ALAxis)axis ++ (ALLayoutConstraintAxis)al_constraintAxisForAxis:(ALAxis)axis { - UILayoutConstraintAxis constraintAxis; + ALLayoutConstraintAxis constraintAxis; switch (axis) { case ALAxisVertical: - constraintAxis = UILayoutConstraintAxisVertical; + constraintAxis = ALLayoutConstraintAxisVertical; break; case ALAxisHorizontal: case ALAxisBaseline: - constraintAxis = UILayoutConstraintAxisHorizontal; + constraintAxis = ALLayoutConstraintAxisHorizontal; break; default: NSAssert(nil, @"Not a valid ALAxis."); @@ -885,14 +896,20 @@ + (UILayoutConstraintAxis)al_constraintAxisForAxis:(ALAxis)axis @return The common superview for the two views. */ -- (UIView *)al_commonSuperviewWithView:(UIView *)peerView +- (ALView *)al_commonSuperviewWithView:(ALView *)peerView { - UIView *commonSuperview = nil; - UIView *startView = self; + ALView *commonSuperview = nil; + ALView *startView = self; do { +#if TARGET_OS_IPHONE if ([peerView isDescendantOfView:startView]) { commonSuperview = startView; } +#else + if ([peerView isDescendantOf:startView]) { + commonSuperview = startView; + } +#endif /* TARGET_OS_IPHONE */ startView = startView.superview; } while (startView && !commonSuperview); NSAssert(commonSuperview, @"Can't constrain two views that do not share a common superview. Make sure that both views have been added into the same view hierarchy."); @@ -907,7 +924,7 @@ - (UIView *)al_commonSuperviewWithView:(UIView *)peerView @param axis The axis along which the views are distributed, used to validate the alignment option. @return The constraint added. */ -- (NSLayoutConstraint *)al_alignToView:(UIView *)peerView withOption:(NSLayoutFormatOptions)alignment forAxis:(ALAxis)axis +- (NSLayoutConstraint *)al_alignToView:(ALView *)peerView withOption:(NSLayoutFormatOptions)alignment forAxis:(ALAxis)axis { NSLayoutConstraint *constraint = nil; switch (alignment) { @@ -955,364 +972,3 @@ - (NSLayoutConstraint *)al_alignToView:(UIView *)peerView withOption:(NSLayoutFo } @end - - -#pragma mark - NSArray+AutoLayout - -@implementation NSArray (AutoLayout) - - -#pragma mark Constrain Multiple Views - -/** - Aligns views in this array to one another along a given edge. - Note: This array must contain at least 2 views, and all views must share a common superview. - - @param edge The edge to which the subviews will be aligned. - @return An array of constraints added. - */ -- (NSArray *)autoAlignViewsToEdge:(ALEdge)edge -{ - NSAssert([self al_containsMinimumNumberOfViews:2], @"This array must contain at least 2 views."); - NSMutableArray *constraints = [NSMutableArray new]; - UIView *previousView = nil; - for (id object in self) { - if ([object isKindOfClass:[UIView class]]) { - UIView *view = (UIView *)object; - view.translatesAutoresizingMaskIntoConstraints = NO; - if (previousView) { - [constraints addObject:[view autoPinEdge:edge toEdge:edge ofView:previousView]]; - } - previousView = view; - } - } - return constraints; -} - -/** - Aligns views in this array to one another along a given axis. - Note: This array must contain at least 2 views, and all views must share a common superview. - - @param axis The axis to which to subviews will be aligned. - @return An array of constraints added. - */ -- (NSArray *)autoAlignViewsToAxis:(ALAxis)axis -{ - NSAssert([self al_containsMinimumNumberOfViews:2], @"This array must contain at least 2 views."); - NSMutableArray *constraints = [NSMutableArray new]; - UIView *previousView = nil; - for (id object in self) { - if ([object isKindOfClass:[UIView class]]) { - UIView *view = (UIView *)object; - view.translatesAutoresizingMaskIntoConstraints = NO; - if (previousView) { - [constraints addObject:[view autoAlignAxis:axis toSameAxisOfView:previousView]]; - } - previousView = view; - } - } - return constraints; -} - -/** - Matches a given dimension of all the views in this array. - Note: This array must contain at least 2 views, and all views must share a common superview. - - @param dimension The dimension to match for all of the subviews. - @return An array of constraints added. - */ -- (NSArray *)autoMatchViewsDimension:(ALDimension)dimension -{ - NSAssert([self al_containsMinimumNumberOfViews:2], @"This array must contain at least 2 views."); - NSMutableArray *constraints = [NSMutableArray new]; - UIView *previousView = nil; - for (id object in self) { - if ([object isKindOfClass:[UIView class]]) { - UIView *view = (UIView *)object; - view.translatesAutoresizingMaskIntoConstraints = NO; - if (previousView) { - [constraints addObject:[view autoMatchDimension:dimension toDimension:dimension ofView:previousView]]; - } - previousView = view; - } - } - return constraints; -} - -/** - Sets the given dimension of all the views in this array to a given size. - Note: This array must contain at least 1 view. - - @param dimension The dimension of each of the subviews to set. - @param size The size to set the given dimension of each subview to. - @return An array of constraints added. - */ -- (NSArray *)autoSetViewsDimension:(ALDimension)dimension toSize:(CGFloat)size -{ - NSAssert([self al_containsMinimumNumberOfViews:1], @"This array must contain at least 1 view."); - NSMutableArray *constraints = [NSMutableArray new]; - for (id object in self) { - if ([object isKindOfClass:[UIView class]]) { - UIView *view = (UIView *)object; - view.translatesAutoresizingMaskIntoConstraints = NO; - [constraints addObject:[view autoSetDimension:dimension toSize:size]]; - } - } - return constraints; -} - - -#pragma mark Distribute Multiple Views - -/** - Distributes the views in this array equally along the selected axis in their superview. - Views will be the same size (variable) in the dimension along the axis and will have spacing (fixed) between them, - including from the first and last views to their superview. - - @param axis The axis along which to distribute the subviews. - @param spacing The fixed amount of spacing between each subview, before the first subview and after the last subview. - @param alignment The way in which the subviews will be aligned. - @return An array of constraints added. - */ -- (NSArray *)autoDistributeViewsAlongAxis:(ALAxis)axis withFixedSpacing:(CGFloat)spacing alignment:(NSLayoutFormatOptions)alignment -{ - return [self autoDistributeViewsAlongAxis:axis withFixedSpacing:spacing insetSpacing:YES alignment:alignment]; -} - -/** - Distributes the views in this array equally along the selected axis in their superview. - Views will be the same size (variable) in the dimension along the axis and will have spacing (fixed) between them. - The first and last views can optionally be inset from their superview by the same amount of spacing as between views. - - @param axis The axis along which to distribute the subviews. - @param spacing The fixed amount of spacing between each subview. - @param shouldSpaceInsets Whether the first and last views should be equally inset from their superview. - @param alignment The way in which the subviews will be aligned. - @return An array of constraints added. - */ -- (NSArray *)autoDistributeViewsAlongAxis:(ALAxis)axis withFixedSpacing:(CGFloat)spacing insetSpacing:(BOOL)shouldSpaceInsets alignment:(NSLayoutFormatOptions)alignment -{ - NSAssert([self al_containsMinimumNumberOfViews:2], @"This array must contain at least 2 views to distribute."); - ALDimension matchedDimension; - ALEdge firstEdge, lastEdge; - switch (axis) { - case ALAxisHorizontal: - case ALAxisBaseline: - matchedDimension = ALDimensionWidth; - firstEdge = ALEdgeLeading; - lastEdge = ALEdgeTrailing; - break; - case ALAxisVertical: - matchedDimension = ALDimensionHeight; - firstEdge = ALEdgeTop; - lastEdge = ALEdgeBottom; - break; - default: - NSAssert(nil, @"Not a valid ALAxis."); - return nil; - } - CGFloat leadingSpacing = shouldSpaceInsets ? spacing : 0.0; - CGFloat trailingSpacing = shouldSpaceInsets ? spacing : 0.0; - - NSMutableArray *constraints = [NSMutableArray new]; - UIView *previousView = nil; - for (id object in self) { - if ([object isKindOfClass:[UIView class]]) { - UIView *view = (UIView *)object; - view.translatesAutoresizingMaskIntoConstraints = NO; - if (previousView) { - // Second, Third, ... View - [constraints addObject:[view autoPinEdge:firstEdge toEdge:lastEdge ofView:previousView withOffset:spacing]]; - [constraints addObject:[view autoMatchDimension:matchedDimension toDimension:matchedDimension ofView:previousView]]; - [constraints addObject:[view al_alignToView:previousView withOption:alignment forAxis:axis]]; - } - else { - // First view - [constraints addObject:[view autoPinEdgeToSuperviewEdge:firstEdge withInset:leadingSpacing]]; - } - previousView = view; - } - } - if (previousView) { - // Last View - [constraints addObject:[previousView autoPinEdgeToSuperviewEdge:lastEdge withInset:trailingSpacing]]; - } - return constraints; -} - -/** - Distributes the views in this array equally along the selected axis in their superview. - Views will be the same size (fixed) in the dimension along the axis and will have spacing (variable) between them, - including from the first and last views to their superview. - - @param axis The axis along which to distribute the subviews. - @param size The fixed size of each subview in the dimension along the given axis. - @param alignment The way in which the subviews will be aligned. - @return An array of constraints added. - */ -- (NSArray *)autoDistributeViewsAlongAxis:(ALAxis)axis withFixedSize:(CGFloat)size alignment:(NSLayoutFormatOptions)alignment -{ - return [self autoDistributeViewsAlongAxis:axis withFixedSize:size insetSpacing:YES alignment:alignment]; -} - -/** - Distributes the views in this array equally along the selected axis in their superview. - Views will be the same size (fixed) in the dimension along the axis and will have spacing (variable) between them. - The first and last views can optionally be inset from their superview by the same amount of spacing as between views. - - @param axis The axis along which to distribute the subviews. - @param size The fixed size of each subview in the dimension along the given axis. - @param shouldSpaceInsets Whether the first and last views should be equally inset from their superview. - @param alignment The way in which the subviews will be aligned. - @return An array of constraints added. - */ -- (NSArray *)autoDistributeViewsAlongAxis:(ALAxis)axis withFixedSize:(CGFloat)size insetSpacing:(BOOL)shouldSpaceInsets alignment:(NSLayoutFormatOptions)alignment -{ - NSAssert([self al_containsMinimumNumberOfViews:2], @"This array must contain at least 2 views to distribute."); - ALDimension fixedDimension; - NSLayoutAttribute attribute; - switch (axis) { - case ALAxisHorizontal: - case ALAxisBaseline: - fixedDimension = ALDimensionWidth; - attribute = NSLayoutAttributeCenterX; - break; - case ALAxisVertical: - fixedDimension = ALDimensionHeight; - attribute = NSLayoutAttributeCenterY; - break; - default: - NSAssert(nil, @"Not a valid ALAxis."); - return nil; - } - BOOL isRightToLeftLanguage = [NSLocale characterDirectionForLanguage:[[NSBundle mainBundle] preferredLocalizations][0]] == NSLocaleLanguageDirectionRightToLeft; - BOOL shouldFlipOrder = isRightToLeftLanguage && (axis != ALAxisVertical); // imitate the effect of leading/trailing when distributing horizontally - - NSMutableArray *constraints = [NSMutableArray new]; - NSArray *views = [self al_copyViewsOnly]; - NSUInteger numberOfViews = [views count]; - UIView *commonSuperview = [views al_commonSuperviewOfViews]; - UIView *previousView = nil; - for (NSUInteger i = 0; i < numberOfViews; i++) { - UIView *view = shouldFlipOrder ? views[numberOfViews - i - 1] : views[i]; - view.translatesAutoresizingMaskIntoConstraints = NO; - [constraints addObject:[view autoSetDimension:fixedDimension toSize:size]]; - CGFloat multiplier, constant; - if (shouldSpaceInsets) { - multiplier = (i * 2.0f + 2.0f) / (numberOfViews + 1.0f); - constant = (multiplier - 1.0f) * size / 2.0f; - } else { - multiplier = (i * 2.0f) / (numberOfViews - 1.0f); - constant = (-multiplier + 1.0f) * size / 2.0f; - } - NSLayoutConstraint *constraint = [NSLayoutConstraint constraintWithItem:view attribute:attribute relatedBy:NSLayoutRelationEqual toItem:commonSuperview attribute:attribute multiplier:multiplier constant:constant]; - [commonSuperview al_addConstraintUsingGlobalPriority:constraint]; - [constraints addObject:constraint]; - if (previousView) { - [constraints addObject:[view al_alignToView:previousView withOption:alignment forAxis:axis]]; - } - previousView = view; - } - return constraints; -} - -#pragma mark Internal Helper Methods - -/** - Returns the common superview for the views in this array. - Raises an exception if the views in this array do not share a common superview. - - @return The common superview for the views in this array. - */ -- (UIView *)al_commonSuperviewOfViews -{ - UIView *commonSuperview = nil; - UIView *previousView = nil; - for (id object in self) { - if ([object isKindOfClass:[UIView class]]) { - UIView *view = (UIView *)object; - if (previousView) { - commonSuperview = [view al_commonSuperviewWithView:commonSuperview]; - } else { - commonSuperview = view; - } - previousView = view; - } - } - NSAssert(commonSuperview, @"Can't constrain views that do not share a common superview. Make sure that all the views in this array have been added into the same view hierarchy."); - return commonSuperview; -} - -/** - Determines whether this array contains a minimum number of views. - - @param minimumNumberOfViews The minimum number of views to check for. - @return YES if this array contains at least the minimum number of views, NO otherwise. - */ -- (BOOL)al_containsMinimumNumberOfViews:(NSUInteger)minimumNumberOfViews -{ - NSUInteger numberOfViews = 0; - for (id object in self) { - if ([object isKindOfClass:[UIView class]]) { - numberOfViews++; - if (numberOfViews >= minimumNumberOfViews) { - return YES; - } - } - } - return numberOfViews >= minimumNumberOfViews; -} - -/** - Creates a copy of this array containing only the view objects in it. - - @return A new array containing only the views that are in this array. - */ -- (NSArray *)al_copyViewsOnly -{ - NSMutableArray *viewsOnlyArray = [NSMutableArray arrayWithCapacity:[self count]]; - for (id object in self) { - if ([object isKindOfClass:[UIView class]]) { - [viewsOnlyArray addObject:object]; - } - } - return viewsOnlyArray; -} - -@end - - -#pragma mark - NSLayoutConstraint+AutoLayout - -@implementation NSLayoutConstraint (AutoLayout) - -/** - Adds the constraint to the appropriate view. - */ -- (void)autoInstall -{ - NSAssert(self.firstItem || self.secondItem, @"Can't install a constraint with nil firstItem and secondItem."); - if (self.firstItem) { - if (self.secondItem) { - NSAssert([self.firstItem isKindOfClass:[UIView class]] && [self.secondItem isKindOfClass:[UIView class]], @"Can only automatically install a constraint if both items are views."); - UIView *commonSuperview = [self.firstItem al_commonSuperviewWithView:self.secondItem]; - [commonSuperview al_addConstraintUsingGlobalPriority:self]; - } else { - NSAssert([self.firstItem isKindOfClass:[UIView class]], @"Can only automatically install a constraint if the item is a view."); - [self.firstItem al_addConstraintUsingGlobalPriority:self]; - } - } else { - NSAssert([self.secondItem isKindOfClass:[UIView class]], @"Can only automatically install a constraint if the item is a view."); - [self.secondItem al_addConstraintUsingGlobalPriority:self]; - } -} - -/** - Removes the constraint from the view it has been added to. - */ -- (void)autoRemove -{ - [UIView autoRemoveConstraint:self]; -} - -@end diff --git a/TableViewCellWithAutoLayout/PureLayout/NSArray+PureLayout.h b/TableViewCellWithAutoLayout/PureLayout/NSArray+PureLayout.h new file mode 100755 index 0000000..da7b070 --- /dev/null +++ b/TableViewCellWithAutoLayout/PureLayout/NSArray+PureLayout.h @@ -0,0 +1,70 @@ +// +// NSArray+PureLayout.h +// v1.0.1 +// https://github.com/smileyborg/PureLayout +// +// Copyright (c) 2012 Richard Turton +// Copyright (c) 2013-2014 Tyler Fox +// +// This code is distributed under the terms and conditions of the MIT license. +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to +// deal in the Software without restriction, including without limitation the +// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or +// sell copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS +// IN THE SOFTWARE. +// + +#import "PureLayoutDefines.h" + + +#pragma mark - NSArray+PureLayout + +/** + A category on NSArray that provides a simple yet powerful interface for applying constraints to groups of views. + */ +@interface NSArray (PureLayout) + + +#pragma mark Constrain Multiple Views + +/** Aligns views in this array to one another along a given edge. */ +- (NSArray *)autoAlignViewsToEdge:(ALEdge)edge; + +/** Aligns views in this array to one another along a given axis. */ +- (NSArray *)autoAlignViewsToAxis:(ALAxis)axis; + +/** Matches a given dimension of all the views in this array. */ +- (NSArray *)autoMatchViewsDimension:(ALDimension)dimension; + +/** Sets the given dimension of all the views in this array to a given size. */ +- (NSArray *)autoSetViewsDimension:(ALDimension)dimension toSize:(CGFloat)size; + + +#pragma mark Distribute Multiple Views + +/** Distributes the views in this array equally along the selected axis in their superview. Views will be the same size (variable) in the dimension along the axis and will have spacing (fixed) between them. */ +- (NSArray *)autoDistributeViewsAlongAxis:(ALAxis)axis withFixedSpacing:(CGFloat)spacing alignment:(NSLayoutFormatOptions)alignment; + +/** Distributes the views in this array equally along the selected axis in their superview. Views will be the same size (variable) in the dimension along the axis and will have spacing (fixed) between them, with optional insets from the first and last views to their superview. */ +- (NSArray *)autoDistributeViewsAlongAxis:(ALAxis)axis withFixedSpacing:(CGFloat)spacing insetSpacing:(BOOL)shouldSpaceInsets alignment:(NSLayoutFormatOptions)alignment; + +/** Distributes the views in this array equally along the selected axis in their superview. Views will be the same size (fixed) in the dimension along the axis and will have spacing (variable) between them. */ +- (NSArray *)autoDistributeViewsAlongAxis:(ALAxis)axis withFixedSize:(CGFloat)size alignment:(NSLayoutFormatOptions)alignment; + +/** Distributes the views in this array equally along the selected axis in their superview. Views will be the same size (fixed) in the dimension along the axis and will have spacing (variable) between them, with optional insets from the first and last views to their superview. */ +- (NSArray *)autoDistributeViewsAlongAxis:(ALAxis)axis withFixedSize:(CGFloat)size insetSpacing:(BOOL)shouldSpaceInsets alignment:(NSLayoutFormatOptions)alignment; + +@end diff --git a/TableViewCellWithAutoLayout/PureLayout/NSArray+PureLayout.m b/TableViewCellWithAutoLayout/PureLayout/NSArray+PureLayout.m new file mode 100755 index 0000000..28ada8e --- /dev/null +++ b/TableViewCellWithAutoLayout/PureLayout/NSArray+PureLayout.m @@ -0,0 +1,358 @@ +// +// NSArray+PureLayout.m +// v1.0.1 +// https://github.com/smileyborg/PureLayout +// +// Copyright (c) 2012 Richard Turton +// Copyright (c) 2013-2014 Tyler Fox +// +// This code is distributed under the terms and conditions of the MIT license. +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to +// deal in the Software without restriction, including without limitation the +// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or +// sell copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS +// IN THE SOFTWARE. +// + +#import "NSArray+PureLayout.h" +#import "ALView+PureLayout.h" +#import "NSLayoutConstraint+PureLayout.h" +#import "PureLayout+Internal.h" + + +#pragma mark - NSArray+PureLayout + +@implementation NSArray (PureLayout) + + +#pragma mark Constrain Multiple Views + +/** + Aligns views in this array to one another along a given edge. + Note: This array must contain at least 2 views, and all views must share a common superview. + + @param edge The edge to which the subviews will be aligned. + @return An array of constraints added. + */ +- (NSArray *)autoAlignViewsToEdge:(ALEdge)edge +{ + NSAssert([self al_containsMinimumNumberOfViews:2], @"This array must contain at least 2 views."); + NSMutableArray *constraints = [NSMutableArray new]; + ALView *previousView = nil; + for (id object in self) { + if ([object isKindOfClass:[ALView class]]) { + ALView *view = (ALView *)object; + view.translatesAutoresizingMaskIntoConstraints = NO; + if (previousView) { + [constraints addObject:[view autoPinEdge:edge toEdge:edge ofView:previousView]]; + } + previousView = view; + } + } + return constraints; +} + +/** + Aligns views in this array to one another along a given axis. + Note: This array must contain at least 2 views, and all views must share a common superview. + + @param axis The axis to which to subviews will be aligned. + @return An array of constraints added. + */ +- (NSArray *)autoAlignViewsToAxis:(ALAxis)axis +{ + NSAssert([self al_containsMinimumNumberOfViews:2], @"This array must contain at least 2 views."); + NSMutableArray *constraints = [NSMutableArray new]; + ALView *previousView = nil; + for (id object in self) { + if ([object isKindOfClass:[ALView class]]) { + ALView *view = (ALView *)object; + view.translatesAutoresizingMaskIntoConstraints = NO; + if (previousView) { + [constraints addObject:[view autoAlignAxis:axis toSameAxisOfView:previousView]]; + } + previousView = view; + } + } + return constraints; +} + +/** + Matches a given dimension of all the views in this array. + Note: This array must contain at least 2 views, and all views must share a common superview. + + @param dimension The dimension to match for all of the subviews. + @return An array of constraints added. + */ +- (NSArray *)autoMatchViewsDimension:(ALDimension)dimension +{ + NSAssert([self al_containsMinimumNumberOfViews:2], @"This array must contain at least 2 views."); + NSMutableArray *constraints = [NSMutableArray new]; + ALView *previousView = nil; + for (id object in self) { + if ([object isKindOfClass:[ALView class]]) { + ALView *view = (ALView *)object; + view.translatesAutoresizingMaskIntoConstraints = NO; + if (previousView) { + [constraints addObject:[view autoMatchDimension:dimension toDimension:dimension ofView:previousView]]; + } + previousView = view; + } + } + return constraints; +} + +/** + Sets the given dimension of all the views in this array to a given size. + Note: This array must contain at least 1 view. + + @param dimension The dimension of each of the subviews to set. + @param size The size to set the given dimension of each subview to. + @return An array of constraints added. + */ +- (NSArray *)autoSetViewsDimension:(ALDimension)dimension toSize:(CGFloat)size +{ + NSAssert([self al_containsMinimumNumberOfViews:1], @"This array must contain at least 1 view."); + NSMutableArray *constraints = [NSMutableArray new]; + for (id object in self) { + if ([object isKindOfClass:[ALView class]]) { + ALView *view = (ALView *)object; + view.translatesAutoresizingMaskIntoConstraints = NO; + [constraints addObject:[view autoSetDimension:dimension toSize:size]]; + } + } + return constraints; +} + + +#pragma mark Distribute Multiple Views + +/** + Distributes the views in this array equally along the selected axis in their superview. + Views will be the same size (variable) in the dimension along the axis and will have spacing (fixed) between them, + including from the first and last views to their superview. + + @param axis The axis along which to distribute the subviews. + @param spacing The fixed amount of spacing between each subview, before the first subview and after the last subview. + @param alignment The way in which the subviews will be aligned. + @return An array of constraints added. + */ +- (NSArray *)autoDistributeViewsAlongAxis:(ALAxis)axis withFixedSpacing:(CGFloat)spacing alignment:(NSLayoutFormatOptions)alignment +{ + return [self autoDistributeViewsAlongAxis:axis withFixedSpacing:spacing insetSpacing:YES alignment:alignment]; +} + +/** + Distributes the views in this array equally along the selected axis in their superview. + Views will be the same size (variable) in the dimension along the axis and will have spacing (fixed) between them. + The first and last views can optionally be inset from their superview by the same amount of spacing as between views. + + @param axis The axis along which to distribute the subviews. + @param spacing The fixed amount of spacing between each subview. + @param shouldSpaceInsets Whether the first and last views should be equally inset from their superview. + @param alignment The way in which the subviews will be aligned. + @return An array of constraints added. + */ +- (NSArray *)autoDistributeViewsAlongAxis:(ALAxis)axis withFixedSpacing:(CGFloat)spacing insetSpacing:(BOOL)shouldSpaceInsets alignment:(NSLayoutFormatOptions)alignment +{ + NSAssert([self al_containsMinimumNumberOfViews:2], @"This array must contain at least 2 views to distribute."); + ALDimension matchedDimension; + ALEdge firstEdge, lastEdge; + switch (axis) { + case ALAxisHorizontal: + case ALAxisBaseline: + matchedDimension = ALDimensionWidth; + firstEdge = ALEdgeLeading; + lastEdge = ALEdgeTrailing; + break; + case ALAxisVertical: + matchedDimension = ALDimensionHeight; + firstEdge = ALEdgeTop; + lastEdge = ALEdgeBottom; + break; + default: + NSAssert(nil, @"Not a valid ALAxis."); + return nil; + } + CGFloat leadingSpacing = shouldSpaceInsets ? spacing : 0.0; + CGFloat trailingSpacing = shouldSpaceInsets ? spacing : 0.0; + + NSMutableArray *constraints = [NSMutableArray new]; + ALView *previousView = nil; + for (id object in self) { + if ([object isKindOfClass:[ALView class]]) { + ALView *view = (ALView *)object; + view.translatesAutoresizingMaskIntoConstraints = NO; + if (previousView) { + // Second, Third, ... View + [constraints addObject:[view autoPinEdge:firstEdge toEdge:lastEdge ofView:previousView withOffset:spacing]]; + [constraints addObject:[view autoMatchDimension:matchedDimension toDimension:matchedDimension ofView:previousView]]; + [constraints addObject:[view al_alignToView:previousView withOption:alignment forAxis:axis]]; + } + else { + // First view + [constraints addObject:[view autoPinEdgeToSuperviewEdge:firstEdge withInset:leadingSpacing]]; + } + previousView = view; + } + } + if (previousView) { + // Last View + [constraints addObject:[previousView autoPinEdgeToSuperviewEdge:lastEdge withInset:trailingSpacing]]; + } + return constraints; +} + +/** + Distributes the views in this array equally along the selected axis in their superview. + Views will be the same size (fixed) in the dimension along the axis and will have spacing (variable) between them, + including from the first and last views to their superview. + + @param axis The axis along which to distribute the subviews. + @param size The fixed size of each subview in the dimension along the given axis. + @param alignment The way in which the subviews will be aligned. + @return An array of constraints added. + */ +- (NSArray *)autoDistributeViewsAlongAxis:(ALAxis)axis withFixedSize:(CGFloat)size alignment:(NSLayoutFormatOptions)alignment +{ + return [self autoDistributeViewsAlongAxis:axis withFixedSize:size insetSpacing:YES alignment:alignment]; +} + +/** + Distributes the views in this array equally along the selected axis in their superview. + Views will be the same size (fixed) in the dimension along the axis and will have spacing (variable) between them. + The first and last views can optionally be inset from their superview by the same amount of spacing as between views. + + @param axis The axis along which to distribute the subviews. + @param size The fixed size of each subview in the dimension along the given axis. + @param shouldSpaceInsets Whether the first and last views should be equally inset from their superview. + @param alignment The way in which the subviews will be aligned. + @return An array of constraints added. + */ +- (NSArray *)autoDistributeViewsAlongAxis:(ALAxis)axis withFixedSize:(CGFloat)size insetSpacing:(BOOL)shouldSpaceInsets alignment:(NSLayoutFormatOptions)alignment +{ + NSAssert([self al_containsMinimumNumberOfViews:2], @"This array must contain at least 2 views to distribute."); + ALDimension fixedDimension; + NSLayoutAttribute attribute; + switch (axis) { + case ALAxisHorizontal: + case ALAxisBaseline: + fixedDimension = ALDimensionWidth; + attribute = NSLayoutAttributeCenterX; + break; + case ALAxisVertical: + fixedDimension = ALDimensionHeight; + attribute = NSLayoutAttributeCenterY; + break; + default: + NSAssert(nil, @"Not a valid ALAxis."); + return nil; + } + BOOL isRightToLeftLanguage = [NSLocale characterDirectionForLanguage:[[NSBundle mainBundle] preferredLocalizations][0]] == NSLocaleLanguageDirectionRightToLeft; + BOOL shouldFlipOrder = isRightToLeftLanguage && (axis != ALAxisVertical); // imitate the effect of leading/trailing when distributing horizontally + + NSMutableArray *constraints = [NSMutableArray new]; + NSArray *views = [self al_copyViewsOnly]; + NSUInteger numberOfViews = [views count]; + ALView *commonSuperview = [views al_commonSuperviewOfViews]; + ALView *previousView = nil; + for (NSUInteger i = 0; i < numberOfViews; i++) { + ALView *view = shouldFlipOrder ? views[numberOfViews - i - 1] : views[i]; + view.translatesAutoresizingMaskIntoConstraints = NO; + [constraints addObject:[view autoSetDimension:fixedDimension toSize:size]]; + CGFloat multiplier, constant; + if (shouldSpaceInsets) { + multiplier = (i * 2.0f + 2.0f) / (numberOfViews + 1.0f); + constant = (multiplier - 1.0f) * size / 2.0f; + } else { + multiplier = (i * 2.0f) / (numberOfViews - 1.0f); + constant = (-multiplier + 1.0f) * size / 2.0f; + } + NSLayoutConstraint *constraint = [NSLayoutConstraint constraintWithItem:view attribute:attribute relatedBy:NSLayoutRelationEqual toItem:commonSuperview attribute:attribute multiplier:multiplier constant:constant]; + [commonSuperview al_addConstraintUsingGlobalPriority:constraint]; + [constraints addObject:constraint]; + if (previousView) { + [constraints addObject:[view al_alignToView:previousView withOption:alignment forAxis:axis]]; + } + previousView = view; + } + return constraints; +} + +#pragma mark Internal Helper Methods + +/** + Returns the common superview for the views in this array. + Raises an exception if the views in this array do not share a common superview. + + @return The common superview for the views in this array. + */ +- (ALView *)al_commonSuperviewOfViews +{ + ALView *commonSuperview = nil; + ALView *previousView = nil; + for (id object in self) { + if ([object isKindOfClass:[ALView class]]) { + ALView *view = (ALView *)object; + if (previousView) { + commonSuperview = [view al_commonSuperviewWithView:commonSuperview]; + } else { + commonSuperview = view; + } + previousView = view; + } + } + NSAssert(commonSuperview, @"Can't constrain views that do not share a common superview. Make sure that all the views in this array have been added into the same view hierarchy."); + return commonSuperview; +} + +/** + Determines whether this array contains a minimum number of views. + + @param minimumNumberOfViews The minimum number of views to check for. + @return YES if this array contains at least the minimum number of views, NO otherwise. + */ +- (BOOL)al_containsMinimumNumberOfViews:(NSUInteger)minimumNumberOfViews +{ + NSUInteger numberOfViews = 0; + for (id object in self) { + if ([object isKindOfClass:[ALView class]]) { + numberOfViews++; + if (numberOfViews >= minimumNumberOfViews) { + return YES; + } + } + } + return numberOfViews >= minimumNumberOfViews; +} + +/** + Creates a copy of this array containing only the view objects in it. + + @return A new array containing only the views that are in this array. + */ +- (NSArray *)al_copyViewsOnly +{ + NSMutableArray *viewsOnlyArray = [NSMutableArray arrayWithCapacity:[self count]]; + for (id object in self) { + if ([object isKindOfClass:[ALView class]]) { + [viewsOnlyArray addObject:object]; + } + } + return viewsOnlyArray; +} + +@end diff --git a/TableViewCellWithAutoLayout/PureLayout/NSLayoutConstraint+PureLayout.h b/TableViewCellWithAutoLayout/PureLayout/NSLayoutConstraint+PureLayout.h new file mode 100755 index 0000000..48ac828 --- /dev/null +++ b/TableViewCellWithAutoLayout/PureLayout/NSLayoutConstraint+PureLayout.h @@ -0,0 +1,45 @@ +// +// NSLayoutConstraint+PureLayout.h +// v1.0.1 +// https://github.com/smileyborg/PureLayout +// +// Copyright (c) 2013-2014 Tyler Fox +// +// This code is distributed under the terms and conditions of the MIT license. +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to +// deal in the Software without restriction, including without limitation the +// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or +// sell copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS +// IN THE SOFTWARE. +// + +#import "PureLayoutDefines.h" + + +#pragma mark - NSLayoutConstraint+PureLayout + +/** + A category on NSLayoutConstraint that allows constraints to be easily removed. + */ +@interface NSLayoutConstraint (PureLayout) + +/** Adds the constraint to the appropriate view. */ +- (void)autoInstall; + +/** Removes the constraint from the view it has been added to. */ +- (void)autoRemove; + +@end diff --git a/TableViewCellWithAutoLayout/PureLayout/NSLayoutConstraint+PureLayout.m b/TableViewCellWithAutoLayout/PureLayout/NSLayoutConstraint+PureLayout.m new file mode 100755 index 0000000..6c58066 --- /dev/null +++ b/TableViewCellWithAutoLayout/PureLayout/NSLayoutConstraint+PureLayout.m @@ -0,0 +1,67 @@ +// +// NSLayoutConstraint+PureLayout.m +// v1.0.1 +// https://github.com/smileyborg/PureLayout +// +// Copyright (c) 2013-2014 Tyler Fox +// +// This code is distributed under the terms and conditions of the MIT license. +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to +// deal in the Software without restriction, including without limitation the +// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or +// sell copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS +// IN THE SOFTWARE. +// + +#import "NSLayoutConstraint+PureLayout.h" +#import "ALView+PureLayout.h" +#import "PureLayout+Internal.h" + + +#pragma mark - NSLayoutConstraint+PureLayout + +@implementation NSLayoutConstraint (PureLayout) + +/** + Adds the constraint to the appropriate view. + */ +- (void)autoInstall +{ + NSAssert(self.firstItem || self.secondItem, @"Can't install a constraint with nil firstItem and secondItem."); + if (self.firstItem) { + if (self.secondItem) { + NSAssert([self.firstItem isKindOfClass:[ALView class]] && [self.secondItem isKindOfClass:[ALView class]], @"Can only automatically install a constraint if both items are views."); + ALView *commonSuperview = [self.firstItem al_commonSuperviewWithView:self.secondItem]; + [commonSuperview al_addConstraintUsingGlobalPriority:self]; + } else { + NSAssert([self.firstItem isKindOfClass:[ALView class]], @"Can only automatically install a constraint if the item is a view."); + [self.firstItem al_addConstraintUsingGlobalPriority:self]; + } + } else { + NSAssert([self.secondItem isKindOfClass:[ALView class]], @"Can only automatically install a constraint if the item is a view."); + [self.secondItem al_addConstraintUsingGlobalPriority:self]; + } +} + +/** + Removes the constraint from the view it has been added to. + */ +- (void)autoRemove +{ + [ALView autoRemoveConstraint:self]; +} + +@end diff --git a/TableViewCellWithAutoLayout/PureLayout/PureLayout+Internal.h b/TableViewCellWithAutoLayout/PureLayout/PureLayout+Internal.h new file mode 100644 index 0000000..1262574 --- /dev/null +++ b/TableViewCellWithAutoLayout/PureLayout/PureLayout+Internal.h @@ -0,0 +1,59 @@ +// +// PureLayout+Internal.h +// v1.0.0 +// https://github.com/smileyborg/PureLayout +// +// Copyright (c) 2014 Tyler Fox +// +// This code is distributed under the terms and conditions of the MIT license. +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to +// deal in the Software without restriction, including without limitation the +// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or +// sell copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS +// IN THE SOFTWARE. +// + +#import "PureLayoutDefines.h" + + +/** + A category that exposes the internal (private) helper methods of the ALView+PureLayout category. + */ +@interface ALView (PureLayoutInternal) + ++ (NSLayoutAttribute)al_attributeForEdge:(ALEdge)edge; ++ (NSLayoutAttribute)al_attributeForAxis:(ALAxis)axis; ++ (NSLayoutAttribute)al_attributeForDimension:(ALDimension)dimension; ++ (NSLayoutAttribute)al_attributeForALAttribute:(NSInteger)ALAttribute; ++ (ALLayoutConstraintAxis)al_constraintAxisForAxis:(ALAxis)axis; + +- (void)al_addConstraintUsingGlobalPriority:(NSLayoutConstraint *)constraint; +- (ALView *)al_commonSuperviewWithView:(ALView *)peerView; +- (NSLayoutConstraint *)al_alignToView:(ALView *)peerView withOption:(NSLayoutFormatOptions)alignment forAxis:(ALAxis)axis; + +@end + + +/** + A category that exposes the internal (private) helper methods of the NSArray+PureLayout category. + */ +@interface NSArray (PureLayoutInternal) + +- (ALView *)al_commonSuperviewOfViews; +- (BOOL)al_containsMinimumNumberOfViews:(NSUInteger)minimumNumberOfViews; +- (NSArray *)al_copyViewsOnly; + +@end diff --git a/TableViewCellWithAutoLayout/PureLayout/PureLayout.h b/TableViewCellWithAutoLayout/PureLayout/PureLayout.h new file mode 100755 index 0000000..421e911 --- /dev/null +++ b/TableViewCellWithAutoLayout/PureLayout/PureLayout.h @@ -0,0 +1,36 @@ +// +// PureLayout.h +// v1.0.1 +// https://github.com/smileyborg/PureLayout +// +// Copyright (c) 2014 Tyler Fox +// +// This code is distributed under the terms and conditions of the MIT license. +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to +// deal in the Software without restriction, including without limitation the +// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or +// sell copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS +// IN THE SOFTWARE. +// + +#ifndef PureLayout_h +#define PureLayout_h + +#import "ALView+PureLayout.h" +#import "NSArray+PureLayout.h" +#import "NSLayoutConstraint+PureLayout.h" + +#endif /* PureLayout_h */ \ No newline at end of file diff --git a/TableViewCellWithAutoLayout/PureLayout/PureLayoutDefines.h b/TableViewCellWithAutoLayout/PureLayout/PureLayoutDefines.h new file mode 100755 index 0000000..e1cd094 --- /dev/null +++ b/TableViewCellWithAutoLayout/PureLayout/PureLayoutDefines.h @@ -0,0 +1,118 @@ +// +// PureLayoutDefines.h +// v1.0.1 +// https://github.com/smileyborg/PureLayout +// +// Copyright (c) 2014 Tyler Fox +// +// This code is distributed under the terms and conditions of the MIT license. +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to +// deal in the Software without restriction, including without limitation the +// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or +// sell copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS +// IN THE SOFTWARE. +// + +#ifndef PureLayoutDefines_h +#define PureLayoutDefines_h + +#import + +#if TARGET_OS_IPHONE + + #import + + #define ALView UIView + #define ALEdgeInsets UIEdgeInsets + #define ALEdgeInsetsZero UIEdgeInsetsZero + #define ALEdgeInsetsMake UIEdgeInsetsMake + #define ALLayoutConstraintAxis UILayoutConstraintAxis + #define ALLayoutConstraintOrientation ALLayoutConstraintAxis + #define ALLayoutConstraintAxisHorizontal UILayoutConstraintAxisHorizontal + #define ALLayoutConstraintAxisVertical UILayoutConstraintAxisVertical + #define ALLayoutConstraintOrientationHorizontal ALLayoutConstraintAxisHorizontal + #define ALLayoutConstraintOrientationVertical ALLayoutConstraintAxisVertical + #define ALLayoutPriority UILayoutPriority + #define ALLayoutPriorityRequired UILayoutPriorityRequired + #define ALLayoutPriorityDefaultHigh UILayoutPriorityDefaultHigh + #define ALLayoutPriorityDefaultLow UILayoutPriorityDefaultLow + #define ALLayoutPriorityFittingSizeLevel UILayoutPriorityFittingSizeLevel + #define ALLayoutPriorityFittingSizeCompression ALLayoutPriorityFittingSizeLevel + +#else + + #import + + #define ALView NSView + #define ALEdgeInsets NSEdgeInsets + #define ALEdgeInsetsZero NSEdgeInsetsMake(0, 0, 0, 0) + #define ALEdgeInsetsMake NSEdgeInsetsMake + #define ALLayoutConstraintOrientation NSLayoutConstraintOrientation + #define ALLayoutConstraintAxis ALLayoutConstraintOrientation + #define ALLayoutConstraintOrientationHorizontal NSLayoutConstraintOrientationHorizontal + #define ALLayoutConstraintOrientationVertical NSLayoutConstraintOrientationVertical + #define ALLayoutConstraintAxisHorizontal ALLayoutConstraintOrientationHorizontal + #define ALLayoutConstraintAxisVertical ALLayoutConstraintOrientationVertical + #define ALLayoutPriority NSLayoutPriority + #define ALLayoutPriorityRequired NSLayoutPriorityRequired + #define ALLayoutPriorityDefaultHigh NSLayoutPriorityDefaultHigh + #define ALLayoutPriorityDefaultLow NSLayoutPriorityDefaultLow + #define ALLayoutPriorityFittingSizeCompression NSLayoutPriorityFittingSizeCompression + #define ALLayoutPriorityFittingSizeLevel ALLayoutPriorityFittingSizeCompression + +#endif /* TARGET_OS_IPHONE */ + + +#pragma mark ALAttributes + +/** Constants that represent edges of a view. */ +typedef NS_ENUM(NSInteger, ALEdge) { + /** The left edge of the view. */ + ALEdgeLeft = NSLayoutAttributeLeft, + /** The right edge of the view. */ + ALEdgeRight = NSLayoutAttributeRight, + /** The top edge of the view. */ + ALEdgeTop = NSLayoutAttributeTop, + /** The bottom edge of the view. */ + ALEdgeBottom = NSLayoutAttributeBottom, + /** The leading edge of the view (left edge for left-to-right languages like English, right edge for right-to-left languages like Arabic). */ + ALEdgeLeading = NSLayoutAttributeLeading, + /** The trailing edge of the view (right edge for left-to-right languages like English, left edge for right-to-left languages like Arabic). */ + ALEdgeTrailing = NSLayoutAttributeTrailing +}; + +/** Constants that represent dimensions of a view. */ +typedef NS_ENUM(NSInteger, ALDimension) { + /** The width of the view. */ + ALDimensionWidth = NSLayoutAttributeWidth, + /** The height of the view. */ + ALDimensionHeight = NSLayoutAttributeHeight +}; + +/** Constants that represent axes of a view. */ +typedef NS_ENUM(NSInteger, ALAxis) { + /** A vertical line through the center of the view. */ + ALAxisVertical = NSLayoutAttributeCenterX, + /** A horizontal line through the center of the view. */ + ALAxisHorizontal = NSLayoutAttributeCenterY, + /** A horizontal line at the text baseline (not applicable to all views). */ + ALAxisBaseline = NSLayoutAttributeBaseline +}; + +/** A block containing method calls to the PureLayout API. Takes no arguments and has no return value. */ +typedef void(^ALConstraintsBlock)(void); + +#endif /* PureLayoutDefines_h */ diff --git a/TableViewCellWithAutoLayout/TableViewController/TableViewCellWithAutoLayout-Bridging-Header.h b/TableViewCellWithAutoLayout/TableViewController/TableViewCellWithAutoLayout-Bridging-Header.h index 8280a41..5e95681 100644 --- a/TableViewCellWithAutoLayout/TableViewController/TableViewCellWithAutoLayout-Bridging-Header.h +++ b/TableViewCellWithAutoLayout/TableViewController/TableViewCellWithAutoLayout-Bridging-Header.h @@ -2,4 +2,4 @@ // Use this file to import your target's public headers that you would like to expose to Swift. // -#import "UIView+AutoLayout.h" +#import "PureLayout.h" From b38f55d6f4e8a9ae5b29ffdfe5d6a30be53af7c8 Mon Sep 17 00:00:00 2001 From: Tyler Fox Date: Tue, 24 Jun 2014 11:00:20 -0700 Subject: [PATCH 11/30] Update README --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 1c53b83..adfb252 100644 --- a/README.md +++ b/README.md @@ -12,7 +12,7 @@ There are two branches in this repository: This sample project displays a table view with cells that each contain a single-line title label and a multi-line body label (each cell's body label displays a random number of lorem ipsum words). -This project utilizes the open source [UIView+AutoLayout API](https://github.com/smileyborg/UIView-AutoLayout) to easily set up constraints in code. +This project utilizes the open source [PureLayout](https://github.com/smileyborg/PureLayout) library to easily set up constraints in code. See the original post on Stack Overflow for more info: From cc07be7e62e4766ba9c7284e14726bd24ae18de2 Mon Sep 17 00:00:00 2001 From: Sebastian Hagedorn Date: Fri, 25 Jul 2014 11:39:08 +0200 Subject: [PATCH 12/30] Changes to fix compiler errors with beta 3 and 4 --- TableViewCellWithAutoLayout/TableViewController/Model.swift | 2 +- .../TableViewController/NibTableViewCell.swift | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/TableViewCellWithAutoLayout/TableViewController/Model.swift b/TableViewCellWithAutoLayout/TableViewController/Model.swift index cc6861a..7d844c7 100644 --- a/TableViewCellWithAutoLayout/TableViewController/Model.swift +++ b/TableViewCellWithAutoLayout/TableViewController/Model.swift @@ -42,7 +42,7 @@ class Model let minimumNumberOfWords = 3 let r = max(minimumNumberOfWords, random() % loremIpsumArray.count) // get a random number r, where: minimumNumberOfWords <= r <= loremIpsumArray.count - let loremIpsumRandom = loremIpsumArray[0..r] // grab a slice of the lorem ipsum array that contains r number of words + let loremIpsumRandom = loremIpsumArray[0.. Date: Fri, 8 Aug 2014 08:41:03 -0700 Subject: [PATCH 13/30] Fix Xcode 6b5 Swift compiler errors --- .../TableViewController/TableViewCell.swift | 26 +++++++++++++------ .../TableViewController.swift | 11 ++++++-- 2 files changed, 27 insertions(+), 10 deletions(-) diff --git a/TableViewCellWithAutoLayout/TableViewController/TableViewCell.swift b/TableViewCellWithAutoLayout/TableViewController/TableViewCell.swift index de4171d..cbe94b0 100644 --- a/TableViewCellWithAutoLayout/TableViewController/TableViewCell.swift +++ b/TableViewCellWithAutoLayout/TableViewController/TableViewCell.swift @@ -16,33 +16,43 @@ class TableViewCell: UITableViewCell var didSetupConstraints = false - var titleLabel: UILabel - var bodyLabel: UILabel + var titleLabel: UILabel = UILabel.newAutoLayoutView() + var bodyLabel: UILabel = UILabel.newAutoLayoutView() - init(style: UITableViewCellStyle, reuseIdentifier: String!) + override init(style: UITableViewCellStyle, reuseIdentifier: String!) + { + super.init(style: style, reuseIdentifier: reuseIdentifier) + + setupViews() + } + + required init(coder aDecoder: NSCoder!) + { + super.init(coder: aDecoder) + + setupViews() + } + + func setupViews() { - titleLabel = UILabel.newAutoLayoutView() titleLabel.lineBreakMode = .ByTruncatingTail titleLabel.numberOfLines = 1 titleLabel.textAlignment = .Left titleLabel.textColor = UIColor.blackColor() titleLabel.backgroundColor = UIColor(red: 0, green: 0, blue: 1, alpha: 0.1) // light blue - bodyLabel = UILabel.newAutoLayoutView() bodyLabel.lineBreakMode = .ByTruncatingTail bodyLabel.numberOfLines = 0 bodyLabel.textAlignment = .Left bodyLabel.textColor = UIColor.darkGrayColor() bodyLabel.backgroundColor = UIColor(red: 1, green: 0, blue: 0, alpha: 0.1) // light red - super.init(style: style, reuseIdentifier: reuseIdentifier) + updateFonts() contentView.addSubview(titleLabel) contentView.addSubview(bodyLabel) contentView.backgroundColor = UIColor(red: 0, green: 1, blue: 0, alpha: 0.1) // light green - - updateFonts() } override func updateConstraints() diff --git a/TableViewCellWithAutoLayout/TableViewController/TableViewController.swift b/TableViewCellWithAutoLayout/TableViewController/TableViewController.swift index a1ecc96..fef49df 100644 --- a/TableViewCellWithAutoLayout/TableViewController/TableViewController.swift +++ b/TableViewCellWithAutoLayout/TableViewController/TableViewController.swift @@ -13,18 +13,25 @@ class TableViewController: UITableViewController var model = Model() - init(nibName nibNameOrNil: String!, bundle nibBundleOrNil: NSBundle!) + override init(nibName nibNameOrNil: String!, bundle nibBundleOrNil: NSBundle!) { super.init(nibName: nibNameOrNil, bundle: nibBundleOrNil) } - init(style: UITableViewStyle) + override init(style: UITableViewStyle) { super.init(style: style) model.populate() } + required init(coder aDecoder: NSCoder!) + { + super.init(coder: aDecoder) + + model.populate() + } + override func viewDidLoad() { super.viewDidLoad() From 153897f7bc7123072d140ccc4d57a0827c27a6ca Mon Sep 17 00:00:00 2001 From: Zachary Gavin Date: Wed, 10 Sep 2014 17:13:02 -0600 Subject: [PATCH 14/30] Updated code for optional conformance due to Apple's API changes, added launch images for 4", 4.7", and 5.5" phones, set NibTableViewCell's bodyLabel preferred width to automatic. --- .../AppIcon.appiconset/Contents.json | 5 +++ .../LaunchImage.launchimage/Contents.json | 31 ++++++++++++- .../Default-568h@2x.png | Bin 0 -> 22219 bytes .../Default-667h@2x.png | Bin 0 -> 23503 bytes .../Default-736h@3x.png | Bin 0 -> 33597 bytes .../TableViewController/NibTableViewCell.xib | 13 ++++-- .../TableViewController/TableViewCell.swift | 2 +- .../TableViewController.swift | 41 +++++++++--------- 8 files changed, 64 insertions(+), 28 deletions(-) create mode 100644 TableViewCellWithAutoLayout/Images.xcassets/LaunchImage.launchimage/Default-568h@2x.png create mode 100644 TableViewCellWithAutoLayout/Images.xcassets/LaunchImage.launchimage/Default-667h@2x.png create mode 100644 TableViewCellWithAutoLayout/Images.xcassets/LaunchImage.launchimage/Default-736h@3x.png diff --git a/TableViewCellWithAutoLayout/Images.xcassets/AppIcon.appiconset/Contents.json b/TableViewCellWithAutoLayout/Images.xcassets/AppIcon.appiconset/Contents.json index 91bf9c1..b7f3352 100644 --- a/TableViewCellWithAutoLayout/Images.xcassets/AppIcon.appiconset/Contents.json +++ b/TableViewCellWithAutoLayout/Images.xcassets/AppIcon.appiconset/Contents.json @@ -15,6 +15,11 @@ "size" : "60x60", "scale" : "2x" }, + { + "idiom" : "iphone", + "size" : "60x60", + "scale" : "3x" + }, { "idiom" : "ipad", "size" : "29x29", diff --git a/TableViewCellWithAutoLayout/Images.xcassets/LaunchImage.launchimage/Contents.json b/TableViewCellWithAutoLayout/Images.xcassets/LaunchImage.launchimage/Contents.json index 6f870a4..a0326e6 100644 --- a/TableViewCellWithAutoLayout/Images.xcassets/LaunchImage.launchimage/Contents.json +++ b/TableViewCellWithAutoLayout/Images.xcassets/LaunchImage.launchimage/Contents.json @@ -1,20 +1,47 @@ { "images" : [ { + "extent" : "full-screen", + "idiom" : "iphone", + "subtype" : "736h", + "filename" : "Default-736h@3x.png", + "minimum-system-version" : "8.0", "orientation" : "portrait", + "scale" : "3x" + }, + { + "orientation" : "landscape", "idiom" : "iphone", "extent" : "full-screen", - "minimum-system-version" : "7.0", + "minimum-system-version" : "8.0", + "subtype" : "736h", + "scale" : "3x" + }, + { + "extent" : "full-screen", + "idiom" : "iphone", + "subtype" : "667h", + "filename" : "Default-667h@2x.png", + "minimum-system-version" : "8.0", + "orientation" : "portrait", "scale" : "2x" }, { "orientation" : "portrait", "idiom" : "iphone", - "subtype" : "retina4", "extent" : "full-screen", "minimum-system-version" : "7.0", "scale" : "2x" }, + { + "extent" : "full-screen", + "idiom" : "iphone", + "subtype" : "retina4", + "filename" : "Default-568h@2x.png", + "minimum-system-version" : "7.0", + "orientation" : "portrait", + "scale" : "2x" + }, { "orientation" : "portrait", "idiom" : "ipad", diff --git a/TableViewCellWithAutoLayout/Images.xcassets/LaunchImage.launchimage/Default-568h@2x.png b/TableViewCellWithAutoLayout/Images.xcassets/LaunchImage.launchimage/Default-568h@2x.png new file mode 100644 index 0000000000000000000000000000000000000000..ff53e814d0d40dcc5d73dd28668f954da28685b2 GIT binary patch literal 22219 zcmeI43piBU`^T3{$|WKap>eI$m>J_bjY&+QayjUt6k}#%YRpV#+$oicR8A>U(!EnI zDN0l#$e@fvlg4U_I$Lqpcj@bPIf=J;YU}K> zj3($rR_~rO>cRTxG1cXBr7_ zzSY~D#7pVC{H(VVl%ML*QIJm+{arV~PFpOZ`n6;XtHA{$I%=1tbSZgFPSkjLd8to% z<09kU0}+txcP-wQ+EK7O6{EXPE|Ll?voQM(jEYPax7_|(*I5PV0dUnli7FA9F&Z2< zqG-y4G*RGPBR*LSc)t-pF9uvx)mx+^pNz)b4JI>H!CP~1n%B)V1gf%tRV;dFVq`M_ zDZTs@5UD2?sp94qD-O=)1J8tBM+);(LsELjU$5^ek_plP{N5Y&P(hv}*;_DuzRrP5 z){}v6%e{lPz*7{nFe%nbafU;RI_0{RNTJRjH#d0cB^_wnXLemQ#iLZ`CXsFye=FW$ zztWA|yYVxYE1v97j`iNG-|Lbq<#7F7+}^)jX&`84=lvs%dgeA0XNK*}CLXam{;pe} zf0FEcmzQc}NuV!!=gJAMtyrGb^&E4}ecGD8x2!29Y_U*CiYv0w+OntBP4Pr|Ht(>a z4|LCWW6Blj?R(zDI9-zLUN zyrrj#SRH7RBMStx@iGP%v3Bw}V7cVzw2XUWFqp|8gmTP05vb*f6s8`yx3wCa)r(A+ zciDX}@lZVg9hM@H=X$;8>oxbRQ>tD!K6is@w>3V>+DNBR^rs4TgYbJomp&{qCE&DQh{XtCb3BdBz-qBV2s z_{!P#FMQ5lpl;XXnpVms3Nh@hRGa+5<;hr53a^)Y(k<~M|oiDyvpVu86u1Zn%h{j!g@YJy$SKr<+x?{4WxM-~B zJg%O&yuuijsAEyvqLxQVSWQ2)uiSB>u0qUS>iol_3CX3}H=;Kd?=RLa?krwbEYjek zu=}V@miDOM73{q3sXD8);9JyMCNO_Dn!8AIQv8$BdWJ}dWC*bb9AR zG>u)p^CTeSW692rdDM^vA&$qK$DTM+4Hn(sZ1bo^(A~ae_a;Wt*Yf!zD>a zE?Js;!$4Z0Lw?zCV&8vx5e9|E`Pj@dFyyOBGy~Ly|GrTpRK!Qz0WrcbLy|S}n zdSzMa`z(BdWb93aGbY*FvtOOL>~KG+Bq_nr@9NnP%=5=1?(I2MpRwccZ%6MQT)nt4 zO>fzK526b%%{#t%JT^IDW0hKld&ZNciDy?h`Zxp~xN~5IQD1l0=9&{Z8v~ENb8hRa z*&0ujjCDE1yv*F+LML8GN_^;*y)t`dvp7$=b3y0wW>c(_v`s8O zc3$kHgcHZ&kCpo;LhogIWge(Bs8kX|(|s4IrKzQn(kQDE0#3YDeWCZll(@}X@6KaV zHoaMHlFg(Yw?+2Z1^t^70K*b9{hIJN`Z@O&eC zZQimxp9_-%C+~$w)1j($ZhaaO8sxYLjr;1Cp*J8o*tJUsC?=_9f>5nJEI)T;GOEtxS_)KoaNc4FRhw3UfMWiXNTQtyUp>JUl)Z`Ub@R*`!9SmrY^By!>4&qu~U^~{s=z0 z>!{4}(4z@QWsij%^_xG*;r%?^{I%FFrA1@vyv3oH*SmMAq=evk?ut`ZmTEz|(EbT& zF~ny&JjhyOcT_R7A9iN%gBB!FtEQR8f6{5c`TEw$TRq8> z_JwIV8apOG$Sd}`zDajOk4R6!jBD5?oZqtJ1+2GOmz$ECJ}$yc-?{i~hLOA5X@Ad! zPgAYarlk=Vf4W@aZGU~Q+^WW^9L48~>H5zukO4yuW+HO>n2R%E#rEAN@-IU#97uGDCluBt+ zczNO6qp+Ypjr|ta!Y;p3dX-;*<9g7~*#$gYQ}lOoA5OMd<9YYBrogZ;B-10=c9+9X6o;KkFO=%ma*TxtH&T-+${p|9$!^-uX-H<+*J^AK$3I+W#WR zr>^a?GOvA2*`<`)kLy2L%TeWODYrt*-uYJ2dm9f=(RaL&vT|0&-&cF%Hm&%hHalWX z#Qw6wDHg5I-WPi7@Y&_h#kGfcgWeYZv7c z!gz0R?FA&81{;amd3D!r?HQtY5kLaeU@>Z#*h)_3lC_HiQ}drhDW8)B9wwB(DYB8i zvK{$8;o<4b@ZPYo;N7@`ZyTu-Mgu2v(bJ|S3607%Np-I|N!^nxYCbvdd_+kGfHZ;W zx`e;PegTQj@iU+?I9`xJupd`=*ahTS!CV@B6~xDQK|V~jg;x8;0xb-aVWG9y*dA}s zwT66|wxRxzOQ?e@J#-b_oS`*~B1H}+2?F>*d>SU$kHzMZf-SWAt zDhsXI!T~W$?42;y9DfL7Y+#I~;|&QIQ*#4?v5`4}Fau+VClGN2JkHP@OCXSpOi2V2 z%;!ssA|?1l_GfsLoT+m^4=1oJw0!w|E(wPV3JNj^A{ub~eQ*SGb8{Tt5NBwJ74*RJ zLfCv-FqX~J9tiR!4i)0j{h3@olf%XcnQ=6z--poj~m zad89#Jnjb~dwXP=pWkiKmHdwY@{o5!cI>5v_jB6xNKCX+!jqM3V}F^p(fb7OA^Yh+9}#L^5+&9HQcf%h^r zCVH6~d-p%&*Ya;dQ#teiVHSN3%@Bmfo6wDo=w2pRb2`mb5SnO&HKUs{ummGx8f0SX zZDi<0{}Otb{F~5@{!GC#L}Lx>BfR^O4)L8Z-wb8TT$(=*64s%G)|WyYTww+m5TT~Oo=G&iaH*lth1m)*$hfashi+?7`B}#Nb^?En z@<9Ay@*j^8kAK{S78wvQku{>MTb2>G=J9-E94uFEXu|H3Tr zXo3IT9Q<4n{r{hXq5P%$(%3!_gM#~#x?dW8ZrTPW^Xr=WvJ`w#(l5(yDGt7@tg+!h)1C^d0ZAPWVm>k zcbHnZhmi!Uiy+f!{Z&mM!J3Dugd6PuN*BSI5TckE8xxJmICwK$;lvDvSWBo(!H&Qau5%_vf(Ppt z!9Cwqx(z7_1ft1s=`h!4=|C1#RUU`Y@)c3`M|s=E*KDG6UBwh2j)d_!GIu}C@y3^FfWP=1_aqeaUt`8c~M+2 zAjl?)3z-khi{gR-K{gR_Ne#X139$ulcm@ex<$TpcSSol86hpUlwg-Sc1prh`iL4~c<7NX>LC0H>}2Q7};u zMFsaZo5|_7wa(6MQ82p8E&Q|F{a_77)f7xe6f|0*!x5g>VZ9^Ysg= zpPPL6V~<=V;UxOAnKpc|pU=<#PBpSx_%hbWRU@xE;aLBc3axSBg7{^2M@D1hs$Zy9 zLBjolYUI@_Ot_J&&>HX0oqwxZe{E$LSyq3^f|096z9S3A8o6rZb%)mY;296C@&1fM z_i^E_g4X!2tqi}gBcuEH;7UL86aL7nRk*8+T!rrAzqTX)n(F^zA2)jd3=9EqFY(XJ nY5lFOvRoWI-Q|65(WAA1UZ=Y0xWfkzAh_)2I8aYnd9MEtP4!Tc literal 0 HcmV?d00001 diff --git a/TableViewCellWithAutoLayout/Images.xcassets/LaunchImage.launchimage/Default-667h@2x.png b/TableViewCellWithAutoLayout/Images.xcassets/LaunchImage.launchimage/Default-667h@2x.png new file mode 100644 index 0000000000000000000000000000000000000000..a3dafc0f5b20106fd790f679e6816a4818ba6e1e GIT binary patch literal 23503 zcmeI4do+~W|Hn7!f}%tsG=@|%X2!V9G=`XRDVKwaD8|f#sWCH|aZjmKq;g6~F5Nrj z5>cX(iX2_3kW@+zr4mJ@;`E&%wE|U;DE^dq2-wBig~v za)Oky6aZj?wH4J70P)uVj5ZuMMo@F@9zpn@B-hH72Y~cs;Xg63H)SdSQn^eE3kL^Z z4xhvG<#18f78WS3KgXNNf&d7v%Ss4xh`X;`_PFiy9chfZxT85|L#OtPP6vq=PYuo8 zW>I*}h}!u1qwj5q8dqC6f70lC;^oUG{-&d|b;9QjQ4wc#r?8GaG3eWN2%B+Pcanc=7ev;Zh^Poj>A$Qlcd z>QmGwfedlrT_-Vp6!3m4ab^^7QdVt|j(9W{bvu~MR0i*eAcxn*)C0;gfK@7fU}{7& z0BPO)G!UURDniNCHAVuQDgvGf-S!mbm#0aY?SH+wBTvRl1Mquy_vq=mlbMe!#VB*uDqf0|O}X7gE_ zF*&N*p0cmDSa9WcSWHe?FU?gtQDR#l9lKv~%oBxe7cHk+OpJ`GoHXWO^mFyHs2N^c z3Q%cLrgB@UXh|!%U7MpO5p&18#>i{Tuo|5!dwl-d`F0wLzh_t(y#*~6n|B74FO|1o z&YE03&$cq@nDn)I7L~qy%HGYo3p#F#^CvIcvE-0t<$_M}P}QQC_Xo2pe;bd}F1y@` zpL1h$$Cb+`sX7XAUUPELnd39cUYwkgIqKZ@cV5{ivBu&%*3%m^xvvXQ?&EjFx@~h? z{~#*kqUvRXr**5(tPU@j^iYA8l&uHZGw6h)6HY{|VR_6^vEwx?s;r%OtR z$9URswIn9VjZ=y|61hEcdE^-LIR}y}?WfL=i{49JcyKH}rCj4$)TYwZQjOA%QnymE zr#^D=hb?n8M*l8n?R7`lQK<#jqS7*j`MdstCF;}S9+fvR#6l!P2p>V=rZpSMW@?9y zIWC&5w%gZc3}kR5#nHZy8nP(F{)pp*V<)PJ&guaQr&B_=g>I^|>@jyb9fR+CgaqXS`gC%5Q*(h9}&pnGQb9Fj$^YN-<{Dm#s^<3|} zBpo_$M)W9L^fB`7graawWeP7|C?FfTAuTj+$dNs0Hp@>b@}ZI<9Eb}Z^x-fV<%khYBB z$JoS7OE`8U?ntG7BJ^Q=_xO8CPnD_(p_#r*R5DaDNEwt>2?596DZkWuX++rWt##`m zDUaSPJI!+1&YNP%mia65FXgXdxv?JKcddQXs@?j!_HOH_S4-=R9ux=U@U2$YwsIfu zY?#_yaO>pFH|OH=;;N3Z|_@IPy~I9+qv#);rV4 zURUT==yP^@;Pkx^X%1Ag-nB<2dL!^CJ(?F3}!bR;w^f!=ycu zmuYy|?$=YiuD+1&b~k4HN? znmv~9KW%pE$t&}wP3Jew+|_Qq+Imaeg*TT&s?XnMu>BXm9rrk~c;gqFCzx3ZjRO1v>&}Ns(_(_J7iFz*lZ`)?@K<6d zNBTjH%Qan$c27=t!}|wx=fFaMp=gOw>&d){@WDX~sDYwy#&ZDX&D z4U?U(wlX{5M3zZrcrZ_O+05)|6uq|cn}^m~Ccn&j@xdTRd28$?{Ku1t#aca~ZNcSl z@+a%gd||J=FOzh|cyU#fzAjURX~TKpXXpExqPpg6)|H~BDo#zYD*4d5qi-`m-M{&4 z)-$PF+xJzNn$~GE!^72E&DTA+oNuYvh^=StyIUVH`>#9k*ToXCfn3rpk2eMW&FK%S z@7{AiVX!>tY<+D@ZODtDKOfr%5CaVAxfgD)x%5+jdW;ly^Ew<})-H0(=Xx1#HjZen!k3Y|AerDm}eu2Mc`)87I z!sqQ>S>5M8en^)qQc?^?;HB0BH)- z*@f?7yNE>R`03IZ94|;W*pDl?>jFSF4d&A5s~|qg3-V#IP0(%UiqR-0!vww5z!qoA zwSat?R-yioQ>dLYJ#-bF$UvJ?q{zV}fdfB?PeTR!vDiFPunD@?FG=uSSdB%adYkZ9 znV{zhJ4CtII-o2#{t(JQ*8oGu>ETgEL|wdrJ`s=CLFwV}1S}qh)gxl?c#^&m32%t{ z`ax5q1mDR13~!Pnb-~x}1SJ!+FQ3mPVX;9$LApT%U5>vG7EdG+u{b@fo*qWf0>cYo z^J&2tHcz9^NxvT|#H0H&xqK#vjS~8$d2s^xCTO&_5={>kO!?Z%ncV$p8^E)!3rBBuy z3Vka?7Q`RP!XKjXIsVQZ4vW$kWrL4sf+w_Dwlq4EEqr8~O~%684=(ngD~L+tLli+U z>SJ(%NW?kgjYv2H62TCIGbG_~L!9)rg!!-)1U`etr~QnVVQt}lI1HwD$WM70Y&qPA ztu4u#&EwP9bjX@Y5zJke$z+g-1Ot775#AU>gBUc7zJakmhKTouFvbRY3}YhQ*qA}2 z^-glQ{2SL)4n05^MPFSr1g?#Y>Bfe7L;*N2Lk32lV2HyIA;CV>Clcuf#teNg1BQOT z>ml-QT-*CI1!;)J8q!8M`d{s01UKJwWyRzPf+u81Pzge-H_1b1{B{9A@c9{ z5#$T8MFo7HtKL@Mcf#X%^Mh#q&^#YOO#E;o_PHFcf%_(7g?X99{6AO)9xd>nt-;T2 zqW}IH48||rm&W#i7!+)O==N9q+_Lp8=I}k$p9;R+gJcGsCjw8H=Zp*l6YCYhEh8#j2bFjN zL2yV6N{5)fO8a7I$OW!9L-f@Ou7`q~DR$s$`c3i}NU;Crm%%yxn_gkQkWOGgL>CcU zqWQqA2rd{9(M1H8Xg)A2f(r&jbP>TNnh(s1;DP}WT|{t+<^!`LxL`m;7ZF^d`M|6Q zE*KEeMFf{CcUqWQqA2rd{9(M1H8Xg)A2f(r&j zbP>TNnh(s1;DP}WT@;B+YVgON5L@sI&mh51In`H1mkNFcilSRN+5*6y2>>q}h>ghw zAOr)z!s|e6l)#Sr48X+trlKG>0Hy?3Q|CDc*S)I2ivcjM1b4Cc8Et)>#?H!&RL#)< zoHvvMAY%1c0JhBqU}_Km7YjxKP^Q{f;rURYYLw}#zzP2P%0Pv%sjxz{cEH*9wLERB bM>1fojf}6PH?2bWM+>dz+fh%Ldv5q2`4zT7 literal 0 HcmV?d00001 diff --git a/TableViewCellWithAutoLayout/Images.xcassets/LaunchImage.launchimage/Default-736h@3x.png b/TableViewCellWithAutoLayout/Images.xcassets/LaunchImage.launchimage/Default-736h@3x.png new file mode 100644 index 0000000000000000000000000000000000000000..f89a1b87d03ddafb51a57f92be59d61178243b4d GIT binary patch literal 33597 zcmeI43sg+~*T+v6q$s*b_vs>uX=a*kGp3OmDs*`&mx!8XPBkS{P)QNhQ-l;3=#>wVYy&05yX{_V5(@0`!szkR-^b&fb! zXZ!K8>aq|7jdygQxj~S09R$f7kQt4PwC!|BLB7WF96SXOB&Q_$CjsqEoeV*;c`Q3S zSJwcpkShq_@-U8eb{HO?>&FU&At}=@uB*)Cmo;e$zgRR-E6t*yN#!GyGpnD z=o{>^i6t0B*Y2J(>cRS0ncB)Z6GuIeEMGd|j~O$zjQ_MgHu{{&q`+g3W-Tc#7IgGC z-+2_$daJKBMUdWg@mXINRC%J)KyhNG=QnEY$d2>&hLXd-?Kl@@HDo*5% z?JJo+-(dd*I~^#X?cMhFeTnrd4_Yk7WKNV#3h5jZf@{3OxfSQ&+58lx_7z3 zO(Mf8@m8X9n#zsByNNTFD>wNuv!rp&8=upVcuKO9yh9vvRGb489 z6Ekd&zV9&>9;dk76=a&(5EzTzdvGHgs+Q+z3XcVr{TRfjoqqjaPBFsI@v1Ae$wJr{&y}!C-WtFzOLfGNf4~aVc~E zy{)y-X~XEGc^AF*5)U>)P^XOq?6cnR`Fhr`sjDHU$8?6Jeg*qIqzl6-1MX0B7_ z)77#!*&1!ap42k-QFyi4j;FlcPAPSr98c}U6{kYEgafLhpQ>!VWIx$%LQHJs#L5R)D|OK}TLZ>)pj&P}lsNqOTu0uI6i019A|yiKeHSx-$HG6 zn|6ehFIKi=87WoIcB)J{CU;}DU1flfx_6Vw+^)NlLZzkK7iHL2&h3^A*D8*Ge<-)| zk8yb8Yo*9(XNMmyt}+k$D@y8`BohRu(py15k5!WM+N9B~_e>_ipGLpMm}OltVn@Qro${kHBI zo|TcTt^j_WVcqPd)7vH5t<#(>4@TTqYBT+47>@1N>z~%2uV{CDX(b*M$E%JB z=eKP$^?bM_CF6n($-8JlZ_L~AEf0*DDoQHeD(N?5chB2>-`LtXBXiusW!1du8P(e| zH!sZ1ls`VPdO=lRwe-qSD?e46WWFQfH|btUzU-e3Yx;Qkj>C^#;BJ_la(RZIHXKZ_ zud1%ns$x`kRZXw1$o!CpPZ}G4Q}L8V{`UOWr!G3*Pq~(oWXisB`XlS?(WrZSPBiB1 zIP}Niy9ZV;Zq71XcHf)mF39prY*oUhCT*E2v- ztYBmC;rDLs{dH+|8RT>1b!5e~G_q>YikEr9;vk}Meo#f5{7XVNN>BeP|15OHkXRUN$+K5P%Q$bsz`{3(RMj2NE?2_lUB@rG6g% z-IaR+U-_nTE?g+%fe!Ingjt*L}SE3D!kcS{s9SE+zS)Z~n^snXS?S)vg6y z%Udn6u5$MA!uWad8cD~FBp#{cC&M4c^^JR=)}&TV49^Z&q?x6eMb4tGN(wsmPW`3f zOH1N5Kf^nZ$oY&`1r2+R9k(U+*%z!VxLmL*a9QA!hn}@>+Kt;^*WPcJdbPODvc4qf zq|jk?Z9DJDj>gHYg?CQfesexCKe6g~1FQC7Iq7=QjiSFdwkbB|-EG-2y`lQ=pd&BU z9^g369MiMSoV7*Eiu}*%1ncaD$KCYnTuFUms z*wi4|q24ijJ89|$K}^@RzpvT95Zri{n7glo|76juTe!;H^4y!=w`W}|DIH)%&$d}= zv;3070mjpNmufJPt`3zo2eePfCs*XOY?q!n2B*MLIJl9v(IbW;cSdISrh=G*^vm@6 zQtb+hbZq)#W%DA;jRZ|0%Nf5>IX+edAEAJ?GS zZ**X6)^_va;H;y=8ZcJ`2uPXzh7s zmCI`=?mgPo)#|>dsEb)sCAJFTN=atG;lT$>A@2EAu3|WW&I` zr&uGEaesv#-gS7~(eT4bhvkoi9cIthaQ-k4H-9a*TV;{V6F+JA)%BiTYUyEkftT{s zmF0Ty6gX{CRvhtad%RG!1^Xgt$voL9#qp0PalI*e<9F0B^&fWS?}Hbl&}ybxCJq>M z+Np;w}}WX4r&3y!_)Xi4C^yo)WVEuR))rte&Q zI>*e*^CaJA;nPgJtZ7-q#RC_w`8i$RtFWrMra<|*a<=jFfoYw8owGe+%c571KLkb8 zG}p*I2w|Uma#C<5L2vfmGrs$p@|w6By&Adwfu97u70vtHEQ8p=br&M!=<%U9i*r^i zQ`mhh>7V3ou3UZ1k{c#i~bT0<*b~~SNak* zt@x`UKWa@>TE(Gs>le>Hl!T}E_to26miri=H@o<9o$mRA#48e4EWPhUkviwSUHK}g zaewC8Ma6^&!CPEM3E95MessgUC)-QvdscMyUsjOUshg`mcmJAOAFbXWf1cm^%+A~E zqA+sXC$d%2r)@nsedl{WB zAkFHNvU!Nsg&@kTP#&GJ3Kn8~VSg6KTCd}Li5`Z< zwANc}?u2*Z*}(xUhj2dZ9`5YH2w%k@G4*CqWhtR#Bmo;1(lMdzK#qVMYOObzmyG-t z4de7MgPRCfS?kRfO^8|ImHzi;!NhSnyGZKL?17nIO5OD-N&Xj~D z5XfehWP%0e%SVqYi~OSSnSNw9+T1VGA(pjXfKbRI<8UD%AtoV26E5E$M<9_%IJ_y& z)D(+sffa;tg!E7>N1#8H7fR>h2qt*kFM^z$#D}rjKaCU!=L92r^5w{WI-$TLj0fY~U;#IX&w%Fy!yKXh z&vt^z_?Cwk#19W^&4hv`Bt--F8yqz+Zt@GTm0hi2qNXRtV;TefKw9D4iV zlRcaYrqP8k6)8qDEFP&uya&OOjJG74T4C`PWITRElA$e8Ih>HfXVQiA-^udbw&*-u zCd)7Ex3Uax`F##2C$b|)Af$5`up^C%9J>jN#Uz_EEv$%mh8dRNYsSQy`Qiy!Un^fr zWX%zo7M4U`lBJpN;6Z*L{zGaSmk}hYqA#hLNNOufk`;+bB4FuEDUHB}d4bcNfY$MwH|LGJzN%O;04lDsuJYge>3Ms9@M&k~z z{(khUBak)NFnDyn02Zx7YrU@v@mq)a)<8rtgX@`0XNX!2l_9EDm`TBXH#)pq-y*++ zv3@*(zejl}|A_Ek&k+&;bHo+=P^!VLew{?X^%I8B`S5Iiq$d8`g*cS*`xta?3Qp9Q z16luuvml@c|L@Mh?=7PL|L0)1ei;FDjz7$#;=Y#d*MZ+VZ9^yX`!)5o75umcDNF|0 zkIQG%g;W-s?hoU59DfRKcyM@5%C~C~*^V2?6P{SjlL>Jm2lNy;0YKpfS89KuCC3L8mMku(!7BMu6=tD%B;=XCqAG*i44*ReC zF?>w_%B-kdU=kD%@g~3}o)5|kaG`*RHvum3d{AD13k5{H32=$$gYp7gC?MiZfJ;0d zlo#Ma0TFKkT;lnlyZ{#ph) zCcq`056TO0p@4`t0WR@;P+ouw1w_0FaEa%G@&a5aAmUAcOFSQx7vMqx5pM!q;`yMw z02c~~coX0f&j;lNxKKdEn*f)1J}581g#sep1h~ZWL3sf#6cF(yz$Km!$_sFzfQUB% zF7bR&UVsY)M7#-biRXjz0$eB{;!Ux*WQX7OggMA7o*~G)oZ}7|nIrFkVi*o?P7uVI z3PFNgNMdvz1chNCX#Pz|LaGdc@Sh-PLPJY&$TA4BZgQl}_6V(eReO*vC80d(amlwTj8e09KfKlJSs=hZ;yFyAd z(jZua{QoP+=d(+IXdpVeQuIHuKoSSXi@qdnHAG+1F&3gP85y?dYr=%V5DezD1Y+6P zfItxy00&f#s1CsD0Ifq*2cSKIYX`VKA`1bC2Oy9{4G{<=Adp0L00a^cNTNCb0tpBt zAdrxS00a^cNTP-a1QHNPqB;Nq2?!)n9RPs@1QHNP$U*=D2?!)nLj(c|2qaM*0D%Mq zlBf=VKmq~@2qa`70D%MqlBgj9fdmASs1ATY0s=`?2S6YJfdm8+vJn373ZzRqGlK)l z@Dm_Hr;TBmQNLxcL0LI=vdrrwj1ltu_1vN7ueT08e?58V`D^^p^VdE@&tG5qqJ8cT zJ-D4Q^x!rK94veQ2UHHS{-dM8>JSNn37~a=_K4I023$M9g%zm-8*qID*GHrd!1WPG zYjFDj1QPP%FSvh1%HTgEkRl7x*d^=%_E`hbl$~`U^=H~C$ghC`DX1q#b1qM*mLT#t M&T*!lu=QF0Us`*DL;wH) literal 0 HcmV?d00001 diff --git a/TableViewCellWithAutoLayout/TableViewController/NibTableViewCell.xib b/TableViewCellWithAutoLayout/TableViewController/NibTableViewCell.xib index 3d7ff40..c5da28e 100644 --- a/TableViewCellWithAutoLayout/TableViewController/NibTableViewCell.xib +++ b/TableViewCellWithAutoLayout/TableViewController/NibTableViewCell.xib @@ -1,12 +1,12 @@ - + - + - + @@ -19,7 +19,7 @@ - + + + + + diff --git a/TableViewCellWithAutoLayout/TableViewController/TableViewCell.swift b/TableViewCellWithAutoLayout/TableViewController/TableViewCell.swift index cbe94b0..386445a 100644 --- a/TableViewCellWithAutoLayout/TableViewController/TableViewCell.swift +++ b/TableViewCellWithAutoLayout/TableViewController/TableViewCell.swift @@ -26,7 +26,7 @@ class TableViewCell: UITableViewCell setupViews() } - required init(coder aDecoder: NSCoder!) + required init(coder aDecoder: NSCoder) { super.init(coder: aDecoder) diff --git a/TableViewCellWithAutoLayout/TableViewController/TableViewController.swift b/TableViewCellWithAutoLayout/TableViewController/TableViewController.swift index fef49df..d48a95a 100644 --- a/TableViewCellWithAutoLayout/TableViewController/TableViewController.swift +++ b/TableViewCellWithAutoLayout/TableViewController/TableViewController.swift @@ -25,7 +25,7 @@ class TableViewController: UITableViewController model.populate() } - required init(coder aDecoder: NSCoder!) + required init(coder aDecoder: NSCoder) { super.init(coder: aDecoder) @@ -50,8 +50,8 @@ class TableViewController: UITableViewController Uncomment ONE of the two lines below to switch between approaches. Make sure that the other line commented out - don't uncomment both! *******************************************************************/ - tableView.registerClass(TableViewCell.self, forCellReuseIdentifier: kCellIdentifier) // uncomment this line to load table view cells programmatically -// tableView.registerNib(UINib(nibName: "NibTableViewCell", bundle: NSBundle.mainBundle()), forCellReuseIdentifier: kCellIdentifier) // uncomment this line to load table view cells from IB +// tableView.registerClass(TableViewCell.self, forCellReuseIdentifier: kCellIdentifier) // uncomment this line to load table view cells programmatically + tableView.registerNib(UINib(nibName: "NibTableViewCell", bundle: NSBundle.mainBundle()), forCellReuseIdentifier: kCellIdentifier) // uncomment this line to load table view cells from IB @@ -106,17 +106,17 @@ class TableViewController: UITableViewController tableView.insertRowsAtIndexPaths([lastIndexPath], withRowAnimation: .Automatic) } - override func numberOfSectionsInTableView(tableView: UITableView!) -> Int + override func numberOfSectionsInTableView(tableView: UITableView) -> Int { return 1 } - override func tableView(tableView: UITableView!, numberOfRowsInSection section: Int) -> Int + override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int { return model.dataArray.count } - override func tableView(tableView: UITableView!, cellForRowAtIndexPath indexPath: NSIndexPath!) -> UITableViewCell! + override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell { // This will be the case for programmatically loaded cells (see viewDidLoad to switch approaches) if let cell: TableViewCell = tableView.dequeueReusableCellWithIdentifier(kCellIdentifier) as? TableViewCell { @@ -134,21 +134,20 @@ class TableViewController: UITableViewController } // This will be the case for interface builder loaded cells (see viewDidLoad to switch approaches) - if let cell: NibTableViewCell = tableView.dequeueReusableCellWithIdentifier(kCellIdentifier) as? NibTableViewCell { - // Configure the cell for this indexPath - cell.updateFonts() - let modelItem = model.dataArray[indexPath.row] - cell.titleLabel.text = modelItem.title - cell.bodyLabel.text = modelItem.body - - // Make sure the constraints have been added to this cell, since it may have just been created from scratch - cell.setNeedsUpdateConstraints() - cell.updateConstraintsIfNeeded() - - return cell - } - - return nil + let cell: NibTableViewCell = tableView.dequeueReusableCellWithIdentifier(kCellIdentifier) as NibTableViewCell + + // Configure the cell for this indexPath + cell.updateFonts() + let modelItem = model.dataArray[indexPath.row] + cell.titleLabel.text = modelItem.title + cell.bodyLabel.text = modelItem.body + + // Make sure the constraints have been added to this cell, since it may have just been created from scratch + cell.setNeedsUpdateConstraints() + cell.updateConstraintsIfNeeded() + + return cell + } /* From 1b19bcca0657510a57f62f0160058eb04e6bd5ed Mon Sep 17 00:00:00 2001 From: Tyler Fox Date: Thu, 11 Sep 2014 19:18:08 -0700 Subject: [PATCH 15/30] Minor logic flow cleanup --- .../TableViewController.swift | 34 ++++++++++--------- 1 file changed, 18 insertions(+), 16 deletions(-) diff --git a/TableViewCellWithAutoLayout/TableViewController/TableViewController.swift b/TableViewCellWithAutoLayout/TableViewController/TableViewController.swift index d48a95a..c9024fc 100644 --- a/TableViewCellWithAutoLayout/TableViewController/TableViewController.swift +++ b/TableViewCellWithAutoLayout/TableViewController/TableViewController.swift @@ -50,8 +50,8 @@ class TableViewController: UITableViewController Uncomment ONE of the two lines below to switch between approaches. Make sure that the other line commented out - don't uncomment both! *******************************************************************/ -// tableView.registerClass(TableViewCell.self, forCellReuseIdentifier: kCellIdentifier) // uncomment this line to load table view cells programmatically - tableView.registerNib(UINib(nibName: "NibTableViewCell", bundle: NSBundle.mainBundle()), forCellReuseIdentifier: kCellIdentifier) // uncomment this line to load table view cells from IB + tableView.registerClass(TableViewCell.self, forCellReuseIdentifier: kCellIdentifier) // uncomment this line to load table view cells programmatically +// tableView.registerNib(UINib(nibName: "NibTableViewCell", bundle: NSBundle.mainBundle()), forCellReuseIdentifier: kCellIdentifier) // uncomment this line to load table view cells from IB @@ -134,20 +134,22 @@ class TableViewController: UITableViewController } // This will be the case for interface builder loaded cells (see viewDidLoad to switch approaches) - let cell: NibTableViewCell = tableView.dequeueReusableCellWithIdentifier(kCellIdentifier) as NibTableViewCell - - // Configure the cell for this indexPath - cell.updateFonts() - let modelItem = model.dataArray[indexPath.row] - cell.titleLabel.text = modelItem.title - cell.bodyLabel.text = modelItem.body - - // Make sure the constraints have been added to this cell, since it may have just been created from scratch - cell.setNeedsUpdateConstraints() - cell.updateConstraintsIfNeeded() - - return cell - + if let cell: NibTableViewCell = tableView.dequeueReusableCellWithIdentifier(kCellIdentifier) as? NibTableViewCell { + // Configure the cell for this indexPath + cell.updateFonts() + let modelItem = model.dataArray[indexPath.row] + cell.titleLabel.text = modelItem.title + cell.bodyLabel.text = modelItem.body + + // Make sure the constraints have been added to this cell, since it may have just been created from scratch + cell.setNeedsUpdateConstraints() + cell.updateConstraintsIfNeeded() + + return cell + } + + assert(false, "The dequeued table view cell was of an unknown type!"); + return UITableViewCell(); } /* From 0fa86095b77a742573de9d748b02a12ab56a9ab3 Mon Sep 17 00:00:00 2001 From: Tyler Fox Date: Thu, 11 Sep 2014 19:22:04 -0700 Subject: [PATCH 16/30] Update PureLayout to v1.1.0 --- .../PureLayout/ALView+PureLayout.h | 2 +- .../PureLayout/ALView+PureLayout.m | 2 +- .../PureLayout/NSArray+PureLayout.h | 5 +++- .../PureLayout/NSArray+PureLayout.m | 24 +++++++++++++++++-- .../NSLayoutConstraint+PureLayout.h | 2 +- .../NSLayoutConstraint+PureLayout.m | 2 +- .../PureLayout/PureLayout+Internal.h | 2 +- .../PureLayout/PureLayout.h | 2 +- .../PureLayout/PureLayoutDefines.h | 2 +- 9 files changed, 33 insertions(+), 10 deletions(-) diff --git a/TableViewCellWithAutoLayout/PureLayout/ALView+PureLayout.h b/TableViewCellWithAutoLayout/PureLayout/ALView+PureLayout.h index 9f7aef1..1c03156 100755 --- a/TableViewCellWithAutoLayout/PureLayout/ALView+PureLayout.h +++ b/TableViewCellWithAutoLayout/PureLayout/ALView+PureLayout.h @@ -1,6 +1,6 @@ // // ALView+PureLayout.h -// v1.0.1 +// v1.1.0 // https://github.com/smileyborg/PureLayout // // Copyright (c) 2012 Richard Turton diff --git a/TableViewCellWithAutoLayout/PureLayout/ALView+PureLayout.m b/TableViewCellWithAutoLayout/PureLayout/ALView+PureLayout.m index 0376801..675f9e8 100755 --- a/TableViewCellWithAutoLayout/PureLayout/ALView+PureLayout.m +++ b/TableViewCellWithAutoLayout/PureLayout/ALView+PureLayout.m @@ -1,6 +1,6 @@ // // ALView+PureLayout.m -// v1.0.1 +// v1.1.0 // https://github.com/smileyborg/PureLayout // // Copyright (c) 2012 Richard Turton diff --git a/TableViewCellWithAutoLayout/PureLayout/NSArray+PureLayout.h b/TableViewCellWithAutoLayout/PureLayout/NSArray+PureLayout.h index da7b070..307bb52 100755 --- a/TableViewCellWithAutoLayout/PureLayout/NSArray+PureLayout.h +++ b/TableViewCellWithAutoLayout/PureLayout/NSArray+PureLayout.h @@ -1,6 +1,6 @@ // // NSArray+PureLayout.h -// v1.0.1 +// v1.1.0 // https://github.com/smileyborg/PureLayout // // Copyright (c) 2012 Richard Turton @@ -61,6 +61,9 @@ /** Distributes the views in this array equally along the selected axis in their superview. Views will be the same size (variable) in the dimension along the axis and will have spacing (fixed) between them, with optional insets from the first and last views to their superview. */ - (NSArray *)autoDistributeViewsAlongAxis:(ALAxis)axis withFixedSpacing:(CGFloat)spacing insetSpacing:(BOOL)shouldSpaceInsets alignment:(NSLayoutFormatOptions)alignment; +/** Distributes the views in this array equally along the selected axis in their superview. Views will have spacing (fixed) between them, with optional insets from the first and last views to their superview, and optionally constrained to the same size in the dimension along the axis. */ +- (NSArray *)autoDistributeViewsAlongAxis:(ALAxis)axis withFixedSpacing:(CGFloat)spacing insetSpacing:(BOOL)shouldSpaceInsets matchedSizes:(BOOL)shouldMatchSizes alignment:(NSLayoutFormatOptions)alignment; + /** Distributes the views in this array equally along the selected axis in their superview. Views will be the same size (fixed) in the dimension along the axis and will have spacing (variable) between them. */ - (NSArray *)autoDistributeViewsAlongAxis:(ALAxis)axis withFixedSize:(CGFloat)size alignment:(NSLayoutFormatOptions)alignment; diff --git a/TableViewCellWithAutoLayout/PureLayout/NSArray+PureLayout.m b/TableViewCellWithAutoLayout/PureLayout/NSArray+PureLayout.m index 28ada8e..4c8cc8f 100755 --- a/TableViewCellWithAutoLayout/PureLayout/NSArray+PureLayout.m +++ b/TableViewCellWithAutoLayout/PureLayout/NSArray+PureLayout.m @@ -1,6 +1,6 @@ // // NSArray+PureLayout.m -// v1.0.1 +// v1.1.0 // https://github.com/smileyborg/PureLayout // // Copyright (c) 2012 Richard Turton @@ -167,6 +167,24 @@ Views will be the same size (variable) in the dimension along the axis and will @return An array of constraints added. */ - (NSArray *)autoDistributeViewsAlongAxis:(ALAxis)axis withFixedSpacing:(CGFloat)spacing insetSpacing:(BOOL)shouldSpaceInsets alignment:(NSLayoutFormatOptions)alignment +{ + return [self autoDistributeViewsAlongAxis:axis withFixedSpacing:spacing insetSpacing:shouldSpaceInsets matchedSizes:YES alignment:alignment]; +} + +/** + Distributes the views in this array equally along the selected axis in their superview. + Views will have fixed spacing between them, and can optionally be constrained to the same size in the dimension along the axis. + The first and last views can optionally be inset from their superview by the same amount of spacing as between views. + + @param axis The axis along which to distribute the subviews. + @param spacing The fixed amount of spacing between each subview. + @param shouldSpaceInsets Whether the first and last views should be equally inset from their superview. + @param shouldMatchSizes Whether all views will be constrained to be the same size in the dimension along the axis. + NOTE: All views must specify an intrinsic content size if passing NO, otherwise the layout will be ambiguous! + @param alignment The way in which the subviews will be aligned. + @return An array of constraints added. + */ +- (NSArray *)autoDistributeViewsAlongAxis:(ALAxis)axis withFixedSpacing:(CGFloat)spacing insetSpacing:(BOOL)shouldSpaceInsets matchedSizes:(BOOL)shouldMatchSizes alignment:(NSLayoutFormatOptions)alignment { NSAssert([self al_containsMinimumNumberOfViews:2], @"This array must contain at least 2 views to distribute."); ALDimension matchedDimension; @@ -199,7 +217,9 @@ - (NSArray *)autoDistributeViewsAlongAxis:(ALAxis)axis withFixedSpacing:(CGFloat if (previousView) { // Second, Third, ... View [constraints addObject:[view autoPinEdge:firstEdge toEdge:lastEdge ofView:previousView withOffset:spacing]]; - [constraints addObject:[view autoMatchDimension:matchedDimension toDimension:matchedDimension ofView:previousView]]; + if (shouldMatchSizes) { + [constraints addObject:[view autoMatchDimension:matchedDimension toDimension:matchedDimension ofView:previousView]]; + } [constraints addObject:[view al_alignToView:previousView withOption:alignment forAxis:axis]]; } else { diff --git a/TableViewCellWithAutoLayout/PureLayout/NSLayoutConstraint+PureLayout.h b/TableViewCellWithAutoLayout/PureLayout/NSLayoutConstraint+PureLayout.h index 48ac828..6733c59 100755 --- a/TableViewCellWithAutoLayout/PureLayout/NSLayoutConstraint+PureLayout.h +++ b/TableViewCellWithAutoLayout/PureLayout/NSLayoutConstraint+PureLayout.h @@ -1,6 +1,6 @@ // // NSLayoutConstraint+PureLayout.h -// v1.0.1 +// v1.1.0 // https://github.com/smileyborg/PureLayout // // Copyright (c) 2013-2014 Tyler Fox diff --git a/TableViewCellWithAutoLayout/PureLayout/NSLayoutConstraint+PureLayout.m b/TableViewCellWithAutoLayout/PureLayout/NSLayoutConstraint+PureLayout.m index 6c58066..cb3fc74 100755 --- a/TableViewCellWithAutoLayout/PureLayout/NSLayoutConstraint+PureLayout.m +++ b/TableViewCellWithAutoLayout/PureLayout/NSLayoutConstraint+PureLayout.m @@ -1,6 +1,6 @@ // // NSLayoutConstraint+PureLayout.m -// v1.0.1 +// v1.1.0 // https://github.com/smileyborg/PureLayout // // Copyright (c) 2013-2014 Tyler Fox diff --git a/TableViewCellWithAutoLayout/PureLayout/PureLayout+Internal.h b/TableViewCellWithAutoLayout/PureLayout/PureLayout+Internal.h index 1262574..4e0e006 100644 --- a/TableViewCellWithAutoLayout/PureLayout/PureLayout+Internal.h +++ b/TableViewCellWithAutoLayout/PureLayout/PureLayout+Internal.h @@ -1,6 +1,6 @@ // // PureLayout+Internal.h -// v1.0.0 +// v1.1.0 // https://github.com/smileyborg/PureLayout // // Copyright (c) 2014 Tyler Fox diff --git a/TableViewCellWithAutoLayout/PureLayout/PureLayout.h b/TableViewCellWithAutoLayout/PureLayout/PureLayout.h index 421e911..cd223b2 100755 --- a/TableViewCellWithAutoLayout/PureLayout/PureLayout.h +++ b/TableViewCellWithAutoLayout/PureLayout/PureLayout.h @@ -1,6 +1,6 @@ // // PureLayout.h -// v1.0.1 +// v1.1.0 // https://github.com/smileyborg/PureLayout // // Copyright (c) 2014 Tyler Fox diff --git a/TableViewCellWithAutoLayout/PureLayout/PureLayoutDefines.h b/TableViewCellWithAutoLayout/PureLayout/PureLayoutDefines.h index e1cd094..86d4f1b 100755 --- a/TableViewCellWithAutoLayout/PureLayout/PureLayoutDefines.h +++ b/TableViewCellWithAutoLayout/PureLayout/PureLayoutDefines.h @@ -1,6 +1,6 @@ // // PureLayoutDefines.h -// v1.0.1 +// v1.1.0 // https://github.com/smileyborg/PureLayout // // Copyright (c) 2014 Tyler Fox From 19a58be49ab9a020cebfc2bb8e679eab810f18f7 Mon Sep 17 00:00:00 2001 From: Tyler Fox Date: Mon, 22 Sep 2014 08:48:31 -0700 Subject: [PATCH 17/30] Call [super updateConstraints] as the final step in updateConstraints --- .../TableViewController/TableViewCell.swift | 56 +++++++++---------- 1 file changed, 28 insertions(+), 28 deletions(-) diff --git a/TableViewCellWithAutoLayout/TableViewController/TableViewCell.swift b/TableViewCellWithAutoLayout/TableViewController/TableViewCell.swift index 386445a..27ca665 100644 --- a/TableViewCellWithAutoLayout/TableViewController/TableViewCell.swift +++ b/TableViewCellWithAutoLayout/TableViewController/TableViewCell.swift @@ -57,35 +57,35 @@ class TableViewCell: UITableViewCell override func updateConstraints() { - super.updateConstraints() - - if didSetupConstraints { return } - - // Note: if the constraints you add below require a larger cell size than the current size (which is likely to be the default size {320, 44}), you'll get an exception. - // As a fix, you can temporarily increase the size of the cell's contentView so that this does not occur using code similar to the line below. - // See here for further discussion: https://github.com/Alex311/TableCellWithAutoLayout/commit/bde387b27e33605eeac3465475d2f2ff9775f163#commitcomment-4633188 - // contentView.bounds = CGRect(x: 0.0, y: 0.0, width: 99999.0, height: 99999.0) - - // Prevent the two UILabels from being compressed below their intrinsic content height - // FIXME 7-Jun-14 Xcode 6b1: Apple Bug Report rdar://17220525: The UILayoutPriority enum is not compatible with Swift yet! - // As a temporary workaround, we're using the raw value of UILayoutPriorityRequired = 1000 - UIView.autoSetPriority(1000) { - self.titleLabel.autoSetContentCompressionResistancePriorityForAxis(.Vertical) - self.bodyLabel.autoSetContentCompressionResistancePriorityForAxis(.Vertical) + if !didSetupConstraints { + // Note: if the constraints you add below require a larger cell size than the current size (which is likely to be the default size {320, 44}), you'll get an exception. + // As a fix, you can temporarily increase the size of the cell's contentView so that this does not occur using code similar to the line below. + // See here for further discussion: https://github.com/Alex311/TableCellWithAutoLayout/commit/bde387b27e33605eeac3465475d2f2ff9775f163#commitcomment-4633188 + // contentView.bounds = CGRect(x: 0.0, y: 0.0, width: 99999.0, height: 99999.0) + + // Prevent the two UILabels from being compressed below their intrinsic content height + // FIXME 7-Jun-14 Xcode 6b1: Apple Bug Report rdar://17220525: The UILayoutPriority enum is not compatible with Swift yet! + // As a temporary workaround, we're using the raw value of UILayoutPriorityRequired = 1000 + UIView.autoSetPriority(1000) { + self.titleLabel.autoSetContentCompressionResistancePriorityForAxis(.Vertical) + self.bodyLabel.autoSetContentCompressionResistancePriorityForAxis(.Vertical) + } + + titleLabel.autoPinEdgeToSuperviewEdge(.Top, withInset: kLabelVerticalInsets) + titleLabel.autoPinEdgeToSuperviewEdge(.Leading, withInset: kLabelHorizontalInsets) + titleLabel.autoPinEdgeToSuperviewEdge(.Trailing, withInset: kLabelHorizontalInsets) + + // This constraint is an inequality so that if the cell is slightly taller than actually required, extra space will go here + bodyLabel.autoPinEdge(.Top, toEdge: .Bottom, ofView: titleLabel, withOffset: 10.0, relation: .GreaterThanOrEqual) + + bodyLabel.autoPinEdgeToSuperviewEdge(.Leading, withInset: kLabelHorizontalInsets) + bodyLabel.autoPinEdgeToSuperviewEdge(.Trailing, withInset: kLabelHorizontalInsets) + bodyLabel.autoPinEdgeToSuperviewEdge(.Bottom, withInset: kLabelVerticalInsets) + + didSetupConstraints = true } - - titleLabel.autoPinEdgeToSuperviewEdge(.Top, withInset: kLabelVerticalInsets) - titleLabel.autoPinEdgeToSuperviewEdge(.Leading, withInset: kLabelHorizontalInsets) - titleLabel.autoPinEdgeToSuperviewEdge(.Trailing, withInset: kLabelHorizontalInsets) - - // This constraint is an inequality so that if the cell is slightly taller than actually required, extra space will go here - bodyLabel.autoPinEdge(.Top, toEdge: .Bottom, ofView: titleLabel, withOffset: 10.0, relation: .GreaterThanOrEqual) - - bodyLabel.autoPinEdgeToSuperviewEdge(.Leading, withInset: kLabelHorizontalInsets) - bodyLabel.autoPinEdgeToSuperviewEdge(.Trailing, withInset: kLabelHorizontalInsets) - bodyLabel.autoPinEdgeToSuperviewEdge(.Bottom, withInset: kLabelVerticalInsets) - - didSetupConstraints = true + + super.updateConstraints() } func updateFonts() From f3251dd48527aaddec3eb76a59a2a9eeeefc4459 Mon Sep 17 00:00:00 2001 From: Tyler Fox Date: Mon, 6 Oct 2014 19:58:50 -0700 Subject: [PATCH 18/30] Fix Xcode 6.1 GM compile issues --- TableViewCellWithAutoLayout/AppDelegate.swift | 2 +- .../TableViewController/TableViewCell.swift | 2 +- .../TableViewController/TableViewController.swift | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/TableViewCellWithAutoLayout/AppDelegate.swift b/TableViewCellWithAutoLayout/AppDelegate.swift index b031fb5..785ef73 100644 --- a/TableViewCellWithAutoLayout/AppDelegate.swift +++ b/TableViewCellWithAutoLayout/AppDelegate.swift @@ -17,7 +17,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate // Override point for customization after application launch. window = UIWindow(frame: UIScreen.mainScreen().bounds) var viewController = TableViewController(style: .Plain) - window!.rootViewController = UINavigationController(rootViewController: viewController) + window!.rootViewController = UINavigationController(rootViewController: viewController!) window!.makeKeyAndVisible() return true } diff --git a/TableViewCellWithAutoLayout/TableViewController/TableViewCell.swift b/TableViewCellWithAutoLayout/TableViewController/TableViewCell.swift index 27ca665..fae56ca 100644 --- a/TableViewCellWithAutoLayout/TableViewController/TableViewCell.swift +++ b/TableViewCellWithAutoLayout/TableViewController/TableViewCell.swift @@ -19,7 +19,7 @@ class TableViewCell: UITableViewCell var titleLabel: UILabel = UILabel.newAutoLayoutView() var bodyLabel: UILabel = UILabel.newAutoLayoutView() - override init(style: UITableViewCellStyle, reuseIdentifier: String!) + override init?(style: UITableViewCellStyle, reuseIdentifier: String!) { super.init(style: style, reuseIdentifier: reuseIdentifier) diff --git a/TableViewCellWithAutoLayout/TableViewController/TableViewController.swift b/TableViewCellWithAutoLayout/TableViewController/TableViewController.swift index c9024fc..f793680 100644 --- a/TableViewCellWithAutoLayout/TableViewController/TableViewController.swift +++ b/TableViewCellWithAutoLayout/TableViewController/TableViewController.swift @@ -18,7 +18,7 @@ class TableViewController: UITableViewController super.init(nibName: nibNameOrNil, bundle: nibBundleOrNil) } - override init(style: UITableViewStyle) + override init?(style: UITableViewStyle) { super.init(style: style) From 0897fe75fe261bca003ef5ed3d48fa7d15f56a5a Mon Sep 17 00:00:00 2001 From: Tyler Fox Date: Sun, 19 Oct 2014 12:08:15 -0700 Subject: [PATCH 19/30] Update PureLayout to latest version (v2.0.1) --- .../PureLayout/ALView+PureLayout.h | 157 +-- .../PureLayout/ALView+PureLayout.m | 897 ++++++++++-------- .../PureLayout/NSArray+PureLayout.h | 51 +- .../PureLayout/NSArray+PureLayout.m | 145 ++- .../NSLayoutConstraint+PureLayout.h | 21 +- .../NSLayoutConstraint+PureLayout.m | 259 ++++- .../PureLayout/PureLayout+Internal.h | 34 +- .../PureLayout/PureLayout.h | 2 +- .../PureLayout/PureLayoutDefines.h | 103 +- 9 files changed, 1139 insertions(+), 530 deletions(-) diff --git a/TableViewCellWithAutoLayout/PureLayout/ALView+PureLayout.h b/TableViewCellWithAutoLayout/PureLayout/ALView+PureLayout.h index 1c03156..fb0b502 100755 --- a/TableViewCellWithAutoLayout/PureLayout/ALView+PureLayout.h +++ b/TableViewCellWithAutoLayout/PureLayout/ALView+PureLayout.h @@ -1,6 +1,6 @@ // // ALView+PureLayout.h -// v1.1.0 +// v2.0.1 // https://github.com/smileyborg/PureLayout // // Copyright (c) 2012 Richard Turton @@ -47,43 +47,32 @@ - (instancetype)initForAutoLayout; -#pragma mark Set Constraint Priority +#pragma mark Create Constraints Without Installing -/** Sets the constraint priority to the given value for all constraints created using the PureLayout API within the given constraints block. - NOTE: This method will have no effect (and will NOT set the priority) on constraints created or added using the SDK directly within the block! */ -+ (void)autoSetPriority:(ALLayoutPriority)priority forConstraints:(ALConstraintsBlock)block; +/** Prevents constraints created in the given constraints block from being automatically installed (activated). + The created constraints returned from each PureLayout API call must be stored, as they are not retained. */ ++ (void)autoCreateConstraintsWithoutInstalling:(ALConstraintsBlock)block; -#pragma mark Remove Constraints +#pragma mark Set Priority For Constraints -/** Removes the given constraint from the view it has been added to. */ -+ (void)autoRemoveConstraint:(NSLayoutConstraint *)constraint; +/** Sets the constraint priority to the given value for all constraints created using the PureLayout API within the given constraints block. + NOTE: This method will have no effect (and will NOT set the priority) on constraints created or added without using the PureLayout API! */ ++ (void)autoSetPriority:(ALLayoutPriority)priority forConstraints:(ALConstraintsBlock)block; -/** Removes the given constraints from the views they have been added to. */ -+ (void)autoRemoveConstraints:(NSArray *)constraints; -/** Removes all explicit constraints that affect the view. - WARNING: Apple's constraint solver is not optimized for large-scale constraint removal; you may encounter major performance issues after using this method. - NOTE: This method preserves implicit constraints, such as intrinsic content size constraints, which you usually do not want to remove. */ -- (void)autoRemoveConstraintsAffectingView; +#pragma mark Set Identifier For Constraints -/** Removes all constraints that affect the view, optionally including implicit constraints. - WARNING: Apple's constraint solver is not optimized for large-scale constraint removal; you may encounter major performance issues after using this method. - NOTE: Implicit constraints are auto-generated lower priority constraints, and you usually do not want to remove these. */ -- (void)autoRemoveConstraintsAffectingViewIncludingImplicitConstraints:(BOOL)shouldRemoveImplicitConstraints; +#if __PureLayout_MinBaseSDK_iOS_8_0 -/** Recursively removes all explicit constraints that affect the view and its subviews. - WARNING: Apple's constraint solver is not optimized for large-scale constraint removal; you may encounter major performance issues after using this method. - NOTE: This method preserves implicit constraints, such as intrinsic content size constraints, which you usually do not want to remove. */ -- (void)autoRemoveConstraintsAffectingViewAndSubviews; +/** Sets the identifier for all constraints created using the PureLayout API within the given constraints block. + NOTE: This method will have no effect (and will NOT set the identifier) on constraints created or added without using the PureLayout API! */ ++ (void)autoSetIdentifier:(NSString *)identifer forConstraints:(ALConstraintsBlock)block; -/** Recursively removes all constraints from the view and its subviews, optionally including implicit constraints. - WARNING: Apple's constraint solver is not optimized for large-scale constraint removal; you may encounter major performance issues after using this method. - NOTE: Implicit constraints are auto-generated lower priority constraints, and you usually do not want to remove these. */ -- (void)autoRemoveConstraintsAffectingViewAndSubviewsIncludingImplicitConstraints:(BOOL)shouldRemoveImplicitConstraints; +#endif /* __PureLayout_MinBaseSDK_iOS_8_0 */ -#pragma mark Center in Superview +#pragma mark Center & Align in Superview /** Centers the view in its superview. */ - (NSArray *)autoCenterInSuperview; @@ -91,13 +80,26 @@ /** Aligns the view to the same axis of its superview. */ - (NSLayoutConstraint *)autoAlignAxisToSuperviewAxis:(ALAxis)axis; +#if __PureLayout_MinBaseSDK_iOS_8_0 + +/** Centers the view in its superview's margins. Available in iOS 8.0 and later. */ +- (NSArray *)autoCenterInSuperviewMargins; + +/** Aligns the view to the corresponding margin axis of its superview. Available in iOS 8.0 and later. */ +- (NSLayoutConstraint *)autoAlignAxisToSuperviewMarginAxis:(ALAxis)axis; + +#endif /* __PureLayout_MinBaseSDK_iOS_8_0 */ + #pragma mark Pin Edges to Superview -/** Pins the given edge of the view to the same edge of the superview with an inset. */ +/** Pins the given edge of the view to the same edge of its superview. */ +- (NSLayoutConstraint *)autoPinEdgeToSuperviewEdge:(ALEdge)edge; + +/** Pins the given edge of the view to the same edge of its superview with an inset. */ - (NSLayoutConstraint *)autoPinEdgeToSuperviewEdge:(ALEdge)edge withInset:(CGFloat)inset; -/** Pins the given edge of the view to the same edge of the superview with an inset as a maximum or minimum. */ +/** Pins the given edge of the view to the same edge of its superview with an inset as a maximum or minimum. */ - (NSLayoutConstraint *)autoPinEdgeToSuperviewEdge:(ALEdge)edge withInset:(CGFloat)inset relation:(NSLayoutRelation)relation; /** Pins the edges of the view to the edges of its superview with the given edge insets. */ @@ -106,44 +108,60 @@ /** Pins 3 of the 4 edges of the view to the edges of its superview with the given edge insets, excluding one edge. */ - (NSArray *)autoPinEdgesToSuperviewEdgesWithInsets:(ALEdgeInsets)insets excludingEdge:(ALEdge)edge; +#if __PureLayout_MinBaseSDK_iOS_8_0 + +/** Pins the given edge of the view to the corresponding margin of its superview. Available in iOS 8.0 and later. */ +- (NSLayoutConstraint *)autoPinEdgeToSuperviewMargin:(ALEdge)edge; + +/** Pins the given edge of the view to the corresponding margin of its superview as a maximum or minimum. Available in iOS 8.0 and later. */ +- (NSLayoutConstraint *)autoPinEdgeToSuperviewMargin:(ALEdge)edge relation:(NSLayoutRelation)relation; + +/** Pins the edges of the view to the margins of its superview. Available in iOS 8.0 and later. */ +- (NSArray *)autoPinEdgesToSuperviewMargins; + +/** Pins 3 of the 4 edges of the view to the margins of its superview excluding one edge. Available in iOS 8.0 and later. */ +- (NSArray *)autoPinEdgesToSuperviewMarginsExcludingEdge:(ALEdge)edge; + +#endif /* __PureLayout_MinBaseSDK_iOS_8_0 */ + #pragma mark Pin Edges /** Pins an edge of the view to a given edge of another view. */ -- (NSLayoutConstraint *)autoPinEdge:(ALEdge)edge toEdge:(ALEdge)toEdge ofView:(ALView *)peerView; +- (NSLayoutConstraint *)autoPinEdge:(ALEdge)edge toEdge:(ALEdge)toEdge ofView:(ALView *)otherView; /** Pins an edge of the view to a given edge of another view with an offset. */ -- (NSLayoutConstraint *)autoPinEdge:(ALEdge)edge toEdge:(ALEdge)toEdge ofView:(ALView *)peerView withOffset:(CGFloat)offset; +- (NSLayoutConstraint *)autoPinEdge:(ALEdge)edge toEdge:(ALEdge)toEdge ofView:(ALView *)otherView withOffset:(CGFloat)offset; /** Pins an edge of the view to a given edge of another view with an offset as a maximum or minimum. */ -- (NSLayoutConstraint *)autoPinEdge:(ALEdge)edge toEdge:(ALEdge)toEdge ofView:(ALView *)peerView withOffset:(CGFloat)offset relation:(NSLayoutRelation)relation; +- (NSLayoutConstraint *)autoPinEdge:(ALEdge)edge toEdge:(ALEdge)toEdge ofView:(ALView *)otherView withOffset:(CGFloat)offset relation:(NSLayoutRelation)relation; #pragma mark Align Axes /** Aligns an axis of the view to the same axis of another view. */ -- (NSLayoutConstraint *)autoAlignAxis:(ALAxis)axis toSameAxisOfView:(ALView *)peerView; +- (NSLayoutConstraint *)autoAlignAxis:(ALAxis)axis toSameAxisOfView:(ALView *)otherView; /** Aligns an axis of the view to the same axis of another view with an offset. */ -- (NSLayoutConstraint *)autoAlignAxis:(ALAxis)axis toSameAxisOfView:(ALView *)peerView withOffset:(CGFloat)offset; +- (NSLayoutConstraint *)autoAlignAxis:(ALAxis)axis toSameAxisOfView:(ALView *)otherView withOffset:(CGFloat)offset; #pragma mark Match Dimensions /** Matches a dimension of the view to a given dimension of another view. */ -- (NSLayoutConstraint *)autoMatchDimension:(ALDimension)dimension toDimension:(ALDimension)toDimension ofView:(ALView *)peerView; +- (NSLayoutConstraint *)autoMatchDimension:(ALDimension)dimension toDimension:(ALDimension)toDimension ofView:(ALView *)otherView; /** Matches a dimension of the view to a given dimension of another view with an offset. */ -- (NSLayoutConstraint *)autoMatchDimension:(ALDimension)dimension toDimension:(ALDimension)toDimension ofView:(ALView *)peerView withOffset:(CGFloat)offset; +- (NSLayoutConstraint *)autoMatchDimension:(ALDimension)dimension toDimension:(ALDimension)toDimension ofView:(ALView *)otherView withOffset:(CGFloat)offset; /** Matches a dimension of the view to a given dimension of another view with an offset as a maximum or minimum. */ -- (NSLayoutConstraint *)autoMatchDimension:(ALDimension)dimension toDimension:(ALDimension)toDimension ofView:(ALView *)peerView withOffset:(CGFloat)offset relation:(NSLayoutRelation)relation; +- (NSLayoutConstraint *)autoMatchDimension:(ALDimension)dimension toDimension:(ALDimension)toDimension ofView:(ALView *)otherView withOffset:(CGFloat)offset relation:(NSLayoutRelation)relation; /** Matches a dimension of the view to a multiple of a given dimension of another view. */ -- (NSLayoutConstraint *)autoMatchDimension:(ALDimension)dimension toDimension:(ALDimension)toDimension ofView:(ALView *)peerView withMultiplier:(CGFloat)multiplier; +- (NSLayoutConstraint *)autoMatchDimension:(ALDimension)dimension toDimension:(ALDimension)toDimension ofView:(ALView *)otherView withMultiplier:(CGFloat)multiplier; /** Matches a dimension of the view to a multiple of a given dimension of another view as a maximum or minimum. */ -- (NSLayoutConstraint *)autoMatchDimension:(ALDimension)dimension toDimension:(ALDimension)toDimension ofView:(ALView *)peerView withMultiplier:(CGFloat)multiplier relation:(NSLayoutRelation)relation; +- (NSLayoutConstraint *)autoMatchDimension:(ALDimension)dimension toDimension:(ALDimension)toDimension ofView:(ALView *)otherView withMultiplier:(CGFloat)multiplier relation:(NSLayoutRelation)relation; #pragma mark Set Dimensions @@ -161,42 +179,75 @@ #pragma mark Set Content Compression Resistance & Hugging /** Sets the priority of content compression resistance for an axis. - NOTE: This method must only be called from within the block passed into the method +[autoSetPriority:forConstraints:] */ + NOTE: This method must be called from within the block passed into the method +[UIView autoSetPriority:forConstraints:] */ - (void)autoSetContentCompressionResistancePriorityForAxis:(ALAxis)axis; /** Sets the priority of content hugging for an axis. - NOTE: This method must only be called from within the block passed into the method +[autoSetPriority:forConstraints:] */ + NOTE: This method must be called from within the block passed into the method +[UIView autoSetPriority:forConstraints:] */ - (void)autoSetContentHuggingPriorityForAxis:(ALAxis)axis; #pragma mark Constrain Any Attributes -/** Constrains an attribute (any ALEdge, ALAxis, or ALDimension) of the view to a given attribute of another view. */ -- (NSLayoutConstraint *)autoConstrainAttribute:(NSInteger)attribute toAttribute:(NSInteger)toAttribute ofView:(ALView *)peerView; +/** Constrains an attribute of the view to a given attribute of another view. */ +- (NSLayoutConstraint *)autoConstrainAttribute:(ALAttribute)attribute toAttribute:(ALAttribute)toAttribute ofView:(ALView *)otherView; -/** Constrains an attribute (any ALEdge, ALAxis, or ALDimension) of the view to a given attribute of another view with an offset. */ -- (NSLayoutConstraint *)autoConstrainAttribute:(NSInteger)attribute toAttribute:(NSInteger)toAttribute ofView:(ALView *)peerView withOffset:(CGFloat)offset; +/** Constrains an attribute of the view to a given attribute of another view with an offset. */ +- (NSLayoutConstraint *)autoConstrainAttribute:(ALAttribute)attribute toAttribute:(ALAttribute)toAttribute ofView:(ALView *)otherView withOffset:(CGFloat)offset; -/** Constrains an attribute (any ALEdge, ALAxis, or ALDimension) of the view to a given attribute of another view with an offset as a maximum or minimum. */ -- (NSLayoutConstraint *)autoConstrainAttribute:(NSInteger)attribute toAttribute:(NSInteger)toAttribute ofView:(ALView *)peerView withOffset:(CGFloat)offset relation:(NSLayoutRelation)relation; +/** Constrains an attribute of the view to a given attribute of another view with an offset as a maximum or minimum. */ +- (NSLayoutConstraint *)autoConstrainAttribute:(ALAttribute)attribute toAttribute:(ALAttribute)toAttribute ofView:(ALView *)otherView withOffset:(CGFloat)offset relation:(NSLayoutRelation)relation; -/** Constrains an attribute (any ALEdge, ALAxis, or ALDimension) of the view to a given attribute of another view with a multiplier. */ -- (NSLayoutConstraint *)autoConstrainAttribute:(NSInteger)attribute toAttribute:(NSInteger)toAttribute ofView:(ALView *)peerView withMultiplier:(CGFloat)multiplier; +/** Constrains an attribute of the view to a given attribute of another view with a multiplier. */ +- (NSLayoutConstraint *)autoConstrainAttribute:(ALAttribute)attribute toAttribute:(ALAttribute)toAttribute ofView:(ALView *)otherView withMultiplier:(CGFloat)multiplier; -/** Constrains an attribute (any ALEdge, ALAxis, or ALDimension) of the view to a given attribute of another view with a multiplier as a maximum or minimum. */ -- (NSLayoutConstraint *)autoConstrainAttribute:(NSInteger)attribute toAttribute:(NSInteger)toAttribute ofView:(ALView *)peerView withMultiplier:(CGFloat)multiplier relation:(NSLayoutRelation)relation; +/** Constrains an attribute of the view to a given attribute of another view with a multiplier as a maximum or minimum. */ +- (NSLayoutConstraint *)autoConstrainAttribute:(ALAttribute)attribute toAttribute:(ALAttribute)toAttribute ofView:(ALView *)otherView withMultiplier:(CGFloat)multiplier relation:(NSLayoutRelation)relation; #pragma mark Pin to Layout Guides (iOS only) #if TARGET_OS_IPHONE -/** Pins the top edge of the view to the top layout guide of the given view controller with an inset. */ +/** Pins the top edge of the view to the top layout guide of the given view controller with an inset. Available on iOS only. */ - (NSLayoutConstraint *)autoPinToTopLayoutGuideOfViewController:(UIViewController *)viewController withInset:(CGFloat)inset; -/** Pins the bottom edge of the view to the bottom layout guide of the given view controller with an inset. */ +/** Pins the top edge of the view to the top layout guide of the given view controller with an inset as a maximum or minimum. Available on iOS only. */ +- (NSLayoutConstraint *)autoPinToTopLayoutGuideOfViewController:(UIViewController *)viewController withInset:(CGFloat)inset relation:(NSLayoutRelation)relation; + +/** Pins the bottom edge of the view to the bottom layout guide of the given view controller with an inset. Available on iOS only. */ - (NSLayoutConstraint *)autoPinToBottomLayoutGuideOfViewController:(UIViewController *)viewController withInset:(CGFloat)inset; +/** Pins the bottom edge of the view to the bottom layout guide of the given view controller with an inset as a maximum or minimum. Available on iOS only. */ +- (NSLayoutConstraint *)autoPinToBottomLayoutGuideOfViewController:(UIViewController *)viewController withInset:(CGFloat)inset relation:(NSLayoutRelation)relation; + #endif /* TARGET_OS_IPHONE */ + +#pragma mark Deprecated Methods + +/** DEPRECATED as of PureLayout v2.0.0. Retain a reference to and remove specific constraints instead, or recreate the view(s) entirely to remove all constraints. + Removes all explicit constraints that affect the view. + WARNING: Apple's constraint solver is not optimized for large-scale constraint removal; you may encounter major performance issues after using this method. + NOTE: This method preserves implicit constraints, such as intrinsic content size constraints, which you usually do not want to remove. */ +- (void)autoRemoveConstraintsAffectingView __attribute__((deprecated)); + +/** DEPRECATED as of PureLayout v2.0.0. Retain a reference to and remove specific constraints instead, or recreate the view(s) entirely to remove all constraints. + Removes all constraints that affect the view, optionally including implicit constraints. + WARNING: Apple's constraint solver is not optimized for large-scale constraint removal; you may encounter major performance issues after using this method. + NOTE: Implicit constraints are auto-generated lower priority constraints, and you usually do not want to remove these. */ +- (void)autoRemoveConstraintsAffectingViewIncludingImplicitConstraints:(BOOL)shouldRemoveImplicitConstraints __attribute__((deprecated)); + +/** DEPRECATED as of PureLayout v2.0.0. Retain a reference to and remove specific constraints instead, or recreate the view(s) entirely to remove all constraints. + Recursively removes all explicit constraints that affect the view and its subviews. + WARNING: Apple's constraint solver is not optimized for large-scale constraint removal; you may encounter major performance issues after using this method. + NOTE: This method preserves implicit constraints, such as intrinsic content size constraints, which you usually do not want to remove. */ +- (void)autoRemoveConstraintsAffectingViewAndSubviews __attribute__((deprecated)); + +/** DEPRECATED as of PureLayout v2.0.0. Retain a reference to and remove specific constraints instead, or recreate the view(s) entirely to remove all constraints. + Recursively removes all constraints from the view and its subviews, optionally including implicit constraints. + WARNING: Apple's constraint solver is not optimized for large-scale constraint removal; you may encounter major performance issues after using this method. + NOTE: Implicit constraints are auto-generated lower priority constraints, and you usually do not want to remove these. */ +- (void)autoRemoveConstraintsAffectingViewAndSubviewsIncludingImplicitConstraints:(BOOL)shouldRemoveImplicitConstraints __attribute__((deprecated)); + @end diff --git a/TableViewCellWithAutoLayout/PureLayout/ALView+PureLayout.m b/TableViewCellWithAutoLayout/PureLayout/ALView+PureLayout.m index 675f9e8..30c0e45 100755 --- a/TableViewCellWithAutoLayout/PureLayout/ALView+PureLayout.m +++ b/TableViewCellWithAutoLayout/PureLayout/ALView+PureLayout.m @@ -1,6 +1,6 @@ // // ALView+PureLayout.m -// v1.1.0 +// v2.0.1 // https://github.com/smileyborg/PureLayout // // Copyright (c) 2012 Richard Turton @@ -29,6 +29,8 @@ #import "ALView+PureLayout.h" #import "NSLayoutConstraint+PureLayout.h" +#import "NSArray+PureLayout.h" +#import "PureLayout+Internal.h" #pragma mark - ALView+PureLayout @@ -61,155 +63,173 @@ - (instancetype)initForAutoLayout } -#pragma mark Set Constraint Priority +#pragma mark Create Constraints Without Installing -/** - A global variable that determines the priority of all constraints created and added by this category. - Defaults to Required, will only be a different value while executing a constraints block passed into the - +[autoSetPriority:forConstraints:] method (as that method will reset the value back to Required - before returning). +/** + A global variable that is incremented when the constraints block passed in to the + +[autoCreateConstraintsWithoutInstalling:] method begins executing, and decremented when the block + finishes executing. As a result, this variable will be 0 when not inside a constraints block, and + greater than 0 when inside a constraints block. NOTE: Access to this variable is not synchronized (and should only be done on the main thread). */ -static ALLayoutPriority _al_globalConstraintPriority = ALLayoutPriorityRequired; +static NSUInteger _al_preventAutomaticConstraintInstallationCount = 0; /** - A global variable that is set to YES while the constraints block passed in to the - +[autoSetPriority:forConstraints:] method is executing. - NOTE: Access to this variable is not synchronized (and should only be done on the main thread). + Accessor for the global state that determines whether automatic constraint installation should be prevented. */ -static BOOL _al_isExecutingConstraintsBlock = NO; ++ (BOOL)al_preventAutomaticConstraintInstallation +{ + return _al_preventAutomaticConstraintInstallationCount > 0; +} -/** - Sets the constraint priority to the given value for all constraints created using the PureLayout - API within the given constraints block. - - NOTE: This method will have no effect (and will NOT set the priority) on constraints created or added - using the SDK directly within the block! +/** + Prevents constraints created in the given constraints block from being automatically installed (activated). + The created constraints returned from each PureLayout API call must be stored, as they are not retained. - @param priority The layout priority to be set on all constraints in the constraints block. - @param block A block of method calls to the PureLayout API that create and add constraints. + @param block A block of method calls to the PureLayout API that create constraints. */ -+ (void)autoSetPriority:(ALLayoutPriority)priority forConstraints:(ALConstraintsBlock)block ++ (void)autoCreateConstraintsWithoutInstalling:(ALConstraintsBlock)block { NSAssert(block, @"The constraints block cannot be nil."); if (block) { - _al_globalConstraintPriority = priority; - _al_isExecutingConstraintsBlock = YES; + _al_preventAutomaticConstraintInstallationCount++; block(); - _al_isExecutingConstraintsBlock = NO; - _al_globalConstraintPriority = ALLayoutPriorityRequired; + _al_preventAutomaticConstraintInstallationCount--; } } -#pragma mark Remove Constraints +#pragma mark Set Priority For Constraints + +/** + A global variable that stores a stack of layout priorities to set on constraints. + When executing a constraints block passed into the +[autoSetPriority:forConstraints:] method, the priority for + that call is pushed onto this stack, and when the block finishes executing, that priority is popped off this + stack. If this stack contains at least 1 priority, the priority at the top of the stack will be set for all + constraints created by this library (even if automatic constraint installation is being prevented). + NOTE: Access to this variable is not synchronized (and should only be done on the main thread). + */ +static NSMutableArray *_al_globalConstraintPriorities = nil; /** - Removes the given constraint from the view it has been added to. - - @param constraint The constraint to remove. + Accessor for the global stack of layout priorities. */ -+ (void)autoRemoveConstraint:(NSLayoutConstraint *)constraint ++ (NSMutableArray *)al_globalConstraintPriorities { - if (constraint.secondItem) { - ALView *commonSuperview = [constraint.firstItem al_commonSuperviewWithView:constraint.secondItem]; - while (commonSuperview) { - if ([commonSuperview.constraints containsObject:constraint]) { - [commonSuperview removeConstraint:constraint]; - return; - } - commonSuperview = commonSuperview.superview; - } - } - else { - [constraint.firstItem removeConstraint:constraint]; - return; + if (!_al_globalConstraintPriorities) { + _al_globalConstraintPriorities = [NSMutableArray new]; } - NSAssert(nil, @"Failed to remove constraint: %@", constraint); + return _al_globalConstraintPriorities; } /** - Removes the given constraints from the views they have been added to. - - @param constraints The constraints to remove. + Returns the current layout priority to use for constraints. + When executing a constraints block passed into +[autoSetPriority:forConstraints:], this will return + the priority for the current block. Otherwise, the default Required priority is returned. */ -+ (void)autoRemoveConstraints:(NSArray *)constraints ++ (ALLayoutPriority)al_currentGlobalConstraintPriority { - for (id object in constraints) { - if ([object isKindOfClass:[NSLayoutConstraint class]]) { - [self autoRemoveConstraint:((NSLayoutConstraint *)object)]; - } else { - NSAssert(nil, @"All constraints to remove must be instances of NSLayoutConstraint."); - } + NSMutableArray *globalConstraintPriorities = [self al_globalConstraintPriorities]; + if ([globalConstraintPriorities count] == 0) { + return ALLayoutPriorityRequired; } + return [[globalConstraintPriorities lastObject] floatValue]; } /** - Removes all explicit constraints that affect the view. - WARNING: Apple's constraint solver is not optimized for large-scale constraint removal; you may encounter major performance issues after using this method. - It is not recommended to use this method to "reset" a view for reuse in a different way with new constraints. Create a new view instead. - NOTE: This method preserves implicit constraints, such as intrinsic content size constraints, which you usually do not want to remove. + Accessor for the global state that determines if we're currently in the scope of a priority constraints block. */ -- (void)autoRemoveConstraintsAffectingView ++ (BOOL)al_isExecutingPriorityConstraintsBlock { - [self autoRemoveConstraintsAffectingViewIncludingImplicitConstraints:NO]; + return [[ALView al_globalConstraintPriorities] count] > 0; } /** - Removes all constraints that affect the view, optionally including implicit constraints. - WARNING: Apple's constraint solver is not optimized for large-scale constraint removal; you may encounter major performance issues after using this method. - It is not recommended to use this method to "reset" a view for reuse in a different way with new constraints. Create a new view instead. - NOTE: Implicit constraints are auto-generated lower priority constraints (such as those that attempt to keep a view at - its intrinsic content size by hugging its content & resisting compression), and you usually do not want to remove these. + Sets the constraint priority to the given value for all constraints created using the PureLayout + API within the given constraints block. - @param shouldRemoveImplicitConstraints Whether implicit constraints should be removed or skipped. + NOTE: This method will have no effect (and will NOT set the priority) on constraints created or added + without using the PureLayout API! + + @param priority The layout priority to be set on all constraints created in the constraints block. + @param block A block of method calls to the PureLayout API that create and install constraints. */ -- (void)autoRemoveConstraintsAffectingViewIncludingImplicitConstraints:(BOOL)shouldRemoveImplicitConstraints ++ (void)autoSetPriority:(ALLayoutPriority)priority forConstraints:(ALConstraintsBlock)block { - NSMutableArray *constraintsToRemove = [NSMutableArray new]; - ALView *startView = self; - do { - for (NSLayoutConstraint *constraint in startView.constraints) { - BOOL isImplicitConstraint = [NSStringFromClass([constraint class]) isEqualToString:@"NSContentSizeLayoutConstraint"]; - if (shouldRemoveImplicitConstraints || !isImplicitConstraint) { - if (constraint.firstItem == self || constraint.secondItem == self) { - [constraintsToRemove addObject:constraint]; - } - } - } - startView = startView.superview; - } while (startView); - [ALView autoRemoveConstraints:constraintsToRemove]; + NSAssert(block, @"The constraints block cannot be nil."); + if (block) { + [[ALView al_globalConstraintPriorities] addObject:@(priority)]; + block(); + [[ALView al_globalConstraintPriorities] removeLastObject]; + } } + +#pragma mark Set Identifier For Constraints + +#if __PureLayout_MinBaseSDK_iOS_8_0 + /** - Recursively removes all explicit constraints that affect the view and its subviews. - WARNING: Apple's constraint solver is not optimized for large-scale constraint removal; you may encounter major performance issues after using this method. - It is not recommended to use this method to "reset" views for reuse in a different way with new constraints. Create a new view instead. - NOTE: This method preserves implicit constraints, such as intrinsic content size constraints, which you usually do not want to remove. + A global variable that stores a stack of identifier strings to set on constraints. + When executing a constraints block passed into the +[autoSetIdentifier:forConstraints:] method, the identifier for + that call is pushed onto this stack, and when the block finishes executing, that identifier is popped off this + stack. If this stack contains at least 1 identifier, the identifier at the top of the stack will be set for all + constraints created by this library (even if automatic constraint installation is being prevented). + NOTE: Access to this variable is not synchronized (and should only be done on the main thread). */ -- (void)autoRemoveConstraintsAffectingViewAndSubviews +static NSMutableArray *_al_globalConstraintIdentifiers = nil; + +/** + Accessor for the global state of constraint identifiers. + */ ++ (NSMutableArray *)al_globalConstraintIdentifiers { - [self autoRemoveConstraintsAffectingViewAndSubviewsIncludingImplicitConstraints:NO]; + if (!_al_globalConstraintIdentifiers) { + _al_globalConstraintIdentifiers = [NSMutableArray new]; + } + return _al_globalConstraintIdentifiers; +} + +/** + Returns the current identifier string to use for constraints. + When executing a constraints block passed into +[autoSetIdentifier:forConstraints:], this will return + the identifier for the current block. Otherwise, nil is returned. + */ ++ (NSString *)al_currentGlobalConstraintIdentifier +{ + NSMutableArray *globalConstraintIdentifiers = [self al_globalConstraintIdentifiers]; + if ([globalConstraintIdentifiers count] == 0) { + return nil; + } + return [globalConstraintIdentifiers lastObject]; } /** - Recursively removes all constraints that affect the view and its subviews, optionally including implicit constraints. - WARNING: Apple's constraint solver is not optimized for large-scale constraint removal; you may encounter major performance issues after using this method. - It is not recommended to use this method to "reset" views for reuse in a different way with new constraints. Create a new view instead. - NOTE: Implicit constraints are auto-generated lower priority constraints (such as those that attempt to keep a view at - its intrinsic content size by hugging its content & resisting compression), and you usually do not want to remove these. + Sets the identifier for all constraints created using the PureLayout API within the given constraints block. - @param shouldRemoveImplicitConstraints Whether implicit constraints should be removed or skipped. + NOTE: This method will have no effect (and will NOT set the identifier) on constraints created or added + without using the PureLayout API! + + @param identifer A string used to identify all constraints created in the constraints block. + @param block A block of method calls to the PureLayout API that create and install constraints. */ -- (void)autoRemoveConstraintsAffectingViewAndSubviewsIncludingImplicitConstraints:(BOOL)shouldRemoveImplicitConstraints ++ (void)autoSetIdentifier:(NSString *)identifer forConstraints:(ALConstraintsBlock)block { - [self autoRemoveConstraintsAffectingViewIncludingImplicitConstraints:shouldRemoveImplicitConstraints]; - for (ALView *subview in self.subviews) { - [subview autoRemoveConstraintsAffectingViewAndSubviewsIncludingImplicitConstraints:shouldRemoveImplicitConstraints]; + NSAssert(block, @"The constraints block cannot be nil."); + NSAssert(identifer, @"The identifier string cannot be nil."); + if (block) { + if (identifer) { + [[ALView al_globalConstraintIdentifiers] addObject:identifer]; + } + block(); + if (identifer) { + [[ALView al_globalConstraintIdentifiers] removeLastObject]; + } } } +#endif /* __PureLayout_MinBaseSDK_iOS_8_0 */ + #pragma mark Center in Superview @@ -237,19 +257,59 @@ - (NSLayoutConstraint *)autoAlignAxisToSuperviewAxis:(ALAxis)axis self.translatesAutoresizingMaskIntoConstraints = NO; ALView *superview = self.superview; NSAssert(superview, @"View's superview must not be nil.\nView: %@", self); - NSLayoutAttribute attribute = [ALView al_attributeForAxis:axis]; - NSLayoutConstraint *constraint = [NSLayoutConstraint constraintWithItem:self attribute:attribute relatedBy:NSLayoutRelationEqual toItem:superview attribute:attribute multiplier:1.0f constant:0.0f]; - [constraint autoInstall]; - return constraint; + return [self autoConstrainAttribute:(ALAttribute)axis toAttribute:(ALAttribute)axis ofView:superview]; } +#if __PureLayout_MinBaseSDK_iOS_8_0 + +/** + Centers the view in its superview, taking into account the layout margins of both the view and its superview. + + @return An array of constraints added. + */ +- (NSArray *)autoCenterInSuperviewMargins +{ + NSMutableArray *constraints = [NSMutableArray new]; + [constraints addObject:[self autoAlignAxisToSuperviewMarginAxis:ALAxisHorizontal]]; + [constraints addObject:[self autoAlignAxisToSuperviewMarginAxis:ALAxisVertical]]; + return constraints; +} + +/** + Aligns the view to the corresponding margin axis of its superview. + + @param axis The axis of this view to align to the corresponding margin axis of its superview. + @return The constraint added. + */ +- (NSLayoutConstraint *)autoAlignAxisToSuperviewMarginAxis:(ALAxis)axis +{ + self.translatesAutoresizingMaskIntoConstraints = NO; + ALView *superview = self.superview; + NSAssert(superview, @"View's superview must not be nil.\nView: %@", self); + ALMarginAxis marginAxis = [NSLayoutConstraint al_marginAxisForAxis:axis]; + return [self autoConstrainAttribute:(ALAttribute)axis toAttribute:(ALAttribute)marginAxis ofView:superview]; +} + +#endif /* __PureLayout_MinBaseSDK_iOS_8_0 */ + #pragma mark Pin Edges to Superview /** - Pins the given edge of the view to the same edge of the superview with an inset. + Pins the given edge of the view to the same edge of its superview. - @param edge The edge of this view and the superview to pin. + @param edge The edge of this view and its superview to pin. + @return The constraint added. + */ +- (NSLayoutConstraint *)autoPinEdgeToSuperviewEdge:(ALEdge)edge +{ + return [self autoPinEdgeToSuperviewEdge:edge withInset:0.0]; +} + +/** + Pins the given edge of the view to the same edge of its superview with an inset. + + @param edge The edge of this view and its superview to pin. @param inset The amount to inset this view's edge from the superview's edge. @return The constraint added. */ @@ -259,9 +319,9 @@ - (NSLayoutConstraint *)autoPinEdgeToSuperviewEdge:(ALEdge)edge withInset:(CGFlo } /** - Pins the given edge of the view to the same edge of the superview with an inset as a maximum or minimum. + Pins the given edge of the view to the same edge of its superview with an inset as a maximum or minimum. - @param edge The edge of this view and the superview to pin. + @param edge The edge of this view and its superview to pin. @param inset The amount to inset this view's edge from the superview's edge. @param relation Whether the inset should be at least, at most, or exactly equal to the given value. @return The constraint added. @@ -287,7 +347,7 @@ - (NSLayoutConstraint *)autoPinEdgeToSuperviewEdge:(ALEdge)edge withInset:(CGFlo Pins the edges of the view to the edges of its superview with the given edge insets. The insets.left corresponds to a leading edge constraint, and insets.right corresponds to a trailing edge constraint. - @param insets The insets for this view's edges from the superview's edges. + @param insets The insets for this view's edges from its superview's edges. @return An array of constraints added. */ - (NSArray *)autoPinEdgesToSuperviewEdgesWithInsets:(ALEdgeInsets)insets @@ -304,9 +364,9 @@ - (NSArray *)autoPinEdgesToSuperviewEdgesWithInsets:(ALEdgeInsets)insets Pins 3 of the 4 edges of the view to the edges of its superview with the given edge insets, excluding one edge. The insets.left corresponds to a leading edge constraint, and insets.right corresponds to a trailing edge constraint. - @param insets The insets for this view's edges from the superview's edges. The inset corresponding to the excluded edge + @param insets The insets for this view's edges from its superview's edges. The inset corresponding to the excluded edge will be ignored. - @param edge The edge of this view to exclude in pinning to the superview; this method will not apply any constraint to it. + @param edge The edge of this view to exclude in pinning to its superview; this method will not apply any constraint to it. @return An array of constraints added. */ - (NSArray *)autoPinEdgesToSuperviewEdgesWithInsets:(ALEdgeInsets)insets excludingEdge:(ALEdge)edge @@ -327,6 +387,84 @@ - (NSArray *)autoPinEdgesToSuperviewEdgesWithInsets:(ALEdgeInsets)insets excludi return constraints; } +#if __PureLayout_MinBaseSDK_iOS_8_0 + +/** + Pins the given edge of the view to the corresponding margin of its superview. + + @param edge The edge of this view to pin to the corresponding margin of its superview. + @return The constraint added. + */ +- (NSLayoutConstraint *)autoPinEdgeToSuperviewMargin:(ALEdge)edge +{ + return [self autoPinEdgeToSuperviewMargin:edge relation:NSLayoutRelationEqual]; +} + +/** + Pins the given edge of the view to the corresponding margin of its superview as a maximum or minimum. + + @param edge The edge of this view to pin to the corresponding margin of its superview. + @param relation Whether the edge should be inset by at least, at most, or exactly the superview's margin. + @return The constraint added. + */ +- (NSLayoutConstraint *)autoPinEdgeToSuperviewMargin:(ALEdge)edge relation:(NSLayoutRelation)relation +{ + self.translatesAutoresizingMaskIntoConstraints = NO; + ALView *superview = self.superview; + NSAssert(superview, @"View's superview must not be nil.\nView: %@", self); + if (edge == ALEdgeBottom || edge == ALEdgeRight || edge == ALEdgeTrailing) { + // The bottom, right, and trailing relations are inverted + if (relation == NSLayoutRelationLessThanOrEqual) { + relation = NSLayoutRelationGreaterThanOrEqual; + } else if (relation == NSLayoutRelationGreaterThanOrEqual) { + relation = NSLayoutRelationLessThanOrEqual; + } + } + ALMargin margin = [NSLayoutConstraint al_marginForEdge:edge]; + return [self autoConstrainAttribute:(ALAttribute)edge toAttribute:(ALAttribute)margin ofView:superview withOffset:0.0 relation:relation]; +} + +/** + Pins the edges of the view to the margins of its superview. + + @return An array of constraints added. + */ +- (NSArray *)autoPinEdgesToSuperviewMargins +{ + NSMutableArray *constraints = [NSMutableArray new]; + [constraints addObject:[self autoPinEdgeToSuperviewMargin:ALEdgeTop]]; + [constraints addObject:[self autoPinEdgeToSuperviewMargin:ALEdgeLeading]]; + [constraints addObject:[self autoPinEdgeToSuperviewMargin:ALEdgeBottom]]; + [constraints addObject:[self autoPinEdgeToSuperviewMargin:ALEdgeTrailing]]; + return constraints; +} + +/** + Pins 3 of the 4 edges of the view to the margins of its superview, excluding one edge. + + @param edge The edge of this view to exclude in pinning to its superview; this method will not apply any constraint to it. + @return An array of constraints added. + */ +- (NSArray *)autoPinEdgesToSuperviewMarginsExcludingEdge:(ALEdge)edge +{ + NSMutableArray *constraints = [NSMutableArray new]; + if (edge != ALEdgeTop) { + [constraints addObject:[self autoPinEdgeToSuperviewMargin:ALEdgeTop]]; + } + if (edge != ALEdgeLeading && edge != ALEdgeLeft) { + [constraints addObject:[self autoPinEdgeToSuperviewMargin:ALEdgeLeading]]; + } + if (edge != ALEdgeBottom) { + [constraints addObject:[self autoPinEdgeToSuperviewMargin:ALEdgeBottom]]; + } + if (edge != ALEdgeTrailing && edge != ALEdgeRight) { + [constraints addObject:[self autoPinEdgeToSuperviewMargin:ALEdgeTrailing]]; + } + return constraints; +} + +#endif /* __PureLayout_MinBaseSDK_iOS_8_0 */ + #pragma mark Pin Edges @@ -334,47 +472,42 @@ - (NSArray *)autoPinEdgesToSuperviewEdgesWithInsets:(ALEdgeInsets)insets excludi Pins an edge of the view to a given edge of another view. @param edge The edge of this view to pin. - @param toEdge The edge of the peer view to pin to. - @param peerView The peer view to pin to. Must be in the same view hierarchy as this view. + @param toEdge The edge of the other view to pin to. + @param otherView The other view to pin to. Must be in the same view hierarchy as this view. @return The constraint added. */ -- (NSLayoutConstraint *)autoPinEdge:(ALEdge)edge toEdge:(ALEdge)toEdge ofView:(ALView *)peerView +- (NSLayoutConstraint *)autoPinEdge:(ALEdge)edge toEdge:(ALEdge)toEdge ofView:(ALView *)otherView { - return [self autoPinEdge:edge toEdge:toEdge ofView:peerView withOffset:0.0f]; + return [self autoPinEdge:edge toEdge:toEdge ofView:otherView withOffset:0.0]; } /** Pins an edge of the view to a given edge of another view with an offset. @param edge The edge of this view to pin. - @param toEdge The edge of the peer view to pin to. - @param peerView The peer view to pin to. Must be in the same view hierarchy as this view. - @param offset The offset between the edge of this view and the edge of the peer view. + @param toEdge The edge of the other view to pin to. + @param otherView The other view to pin to. Must be in the same view hierarchy as this view. + @param offset The offset between the edge of this view and the edge of the other view. @return The constraint added. */ -- (NSLayoutConstraint *)autoPinEdge:(ALEdge)edge toEdge:(ALEdge)toEdge ofView:(ALView *)peerView withOffset:(CGFloat)offset +- (NSLayoutConstraint *)autoPinEdge:(ALEdge)edge toEdge:(ALEdge)toEdge ofView:(ALView *)otherView withOffset:(CGFloat)offset { - return [self autoPinEdge:edge toEdge:toEdge ofView:peerView withOffset:offset relation:NSLayoutRelationEqual]; + return [self autoPinEdge:edge toEdge:toEdge ofView:otherView withOffset:offset relation:NSLayoutRelationEqual]; } /** Pins an edge of the view to a given edge of another view with an offset as a maximum or minimum. @param edge The edge of this view to pin. - @param toEdge The edge of the peer view to pin to. - @param peerView The peer view to pin to. Must be in the same view hierarchy as this view. - @param offset The offset between the edge of this view and the edge of the peer view. + @param toEdge The edge of the other view to pin to. + @param otherView The other view to pin to. Must be in the same view hierarchy as this view. + @param offset The offset between the edge of this view and the edge of the other view. @param relation Whether the offset should be at least, at most, or exactly equal to the given value. @return The constraint added. */ -- (NSLayoutConstraint *)autoPinEdge:(ALEdge)edge toEdge:(ALEdge)toEdge ofView:(ALView *)peerView withOffset:(CGFloat)offset relation:(NSLayoutRelation)relation +- (NSLayoutConstraint *)autoPinEdge:(ALEdge)edge toEdge:(ALEdge)toEdge ofView:(ALView *)otherView withOffset:(CGFloat)offset relation:(NSLayoutRelation)relation { - self.translatesAutoresizingMaskIntoConstraints = NO; - NSLayoutAttribute attribute = [ALView al_attributeForEdge:edge]; - NSLayoutAttribute toAttribute = [ALView al_attributeForEdge:toEdge]; - NSLayoutConstraint *constraint = [NSLayoutConstraint constraintWithItem:self attribute:attribute relatedBy:relation toItem:peerView attribute:toAttribute multiplier:1.0f constant:offset]; - [constraint autoInstall]; - return constraint; + return [self autoConstrainAttribute:(ALAttribute)edge toAttribute:(ALAttribute)toEdge ofView:otherView withOffset:offset relation:relation]; } @@ -383,30 +516,26 @@ - (NSLayoutConstraint *)autoPinEdge:(ALEdge)edge toEdge:(ALEdge)toEdge ofView:(A /** Aligns an axis of the view to the same axis of another view. - @param axis The axis of this view and the peer view to align. - @param peerView The peer view to align to. Must be in the same view hierarchy as this view. + @param axis The axis of this view and the other view to align. + @param otherView The other view to align to. Must be in the same view hierarchy as this view. @return The constraint added. */ -- (NSLayoutConstraint *)autoAlignAxis:(ALAxis)axis toSameAxisOfView:(ALView *)peerView +- (NSLayoutConstraint *)autoAlignAxis:(ALAxis)axis toSameAxisOfView:(ALView *)otherView { - return [self autoAlignAxis:axis toSameAxisOfView:peerView withOffset:0.0f]; + return [self autoAlignAxis:axis toSameAxisOfView:otherView withOffset:0.0]; } /** Aligns an axis of the view to the same axis of another view with an offset. - @param axis The axis of this view and the peer view to align. - @param peerView The peer view to align to. Must be in the same view hierarchy as this view. - @param offset The offset between the axis of this view and the axis of the peer view. + @param axis The axis of this view and the other view to align. + @param otherView The other view to align to. Must be in the same view hierarchy as this view. + @param offset The offset between the axis of this view and the axis of the other view. @return The constraint added. */ -- (NSLayoutConstraint *)autoAlignAxis:(ALAxis)axis toSameAxisOfView:(ALView *)peerView withOffset:(CGFloat)offset +- (NSLayoutConstraint *)autoAlignAxis:(ALAxis)axis toSameAxisOfView:(ALView *)otherView withOffset:(CGFloat)offset { - self.translatesAutoresizingMaskIntoConstraints = NO; - NSLayoutAttribute attribute = [ALView al_attributeForAxis:axis]; - NSLayoutConstraint *constraint = [NSLayoutConstraint constraintWithItem:self attribute:attribute relatedBy:NSLayoutRelationEqual toItem:peerView attribute:attribute multiplier:1.0f constant:offset]; - [constraint autoInstall]; - return constraint; + return [self autoConstrainAttribute:(ALAttribute)axis toAttribute:(ALAttribute)axis ofView:otherView withOffset:offset]; } @@ -416,81 +545,71 @@ - (NSLayoutConstraint *)autoAlignAxis:(ALAxis)axis toSameAxisOfView:(ALView *)pe Matches a dimension of the view to a given dimension of another view. @param dimension The dimension of this view to pin. - @param toDimension The dimension of the peer view to pin to. - @param peerView The peer view to match to. Must be in the same view hierarchy as this view. + @param toDimension The dimension of the other view to pin to. + @param otherView The other view to match to. Must be in the same view hierarchy as this view. @return The constraint added. */ -- (NSLayoutConstraint *)autoMatchDimension:(ALDimension)dimension toDimension:(ALDimension)toDimension ofView:(ALView *)peerView +- (NSLayoutConstraint *)autoMatchDimension:(ALDimension)dimension toDimension:(ALDimension)toDimension ofView:(ALView *)otherView { - return [self autoMatchDimension:dimension toDimension:toDimension ofView:peerView withOffset:0.0f]; + return [self autoMatchDimension:dimension toDimension:toDimension ofView:otherView withOffset:0.0]; } /** Matches a dimension of the view to a given dimension of another view with an offset. @param dimension The dimension of this view to pin. - @param toDimension The dimension of the peer view to pin to. - @param peerView The peer view to match to. Must be in the same view hierarchy as this view. - @param offset The offset between the dimension of this view and the dimension of the peer view. + @param toDimension The dimension of the other view to pin to. + @param otherView The other view to match to. Must be in the same view hierarchy as this view. + @param offset The offset between the dimension of this view and the dimension of the other view. @return The constraint added. */ -- (NSLayoutConstraint *)autoMatchDimension:(ALDimension)dimension toDimension:(ALDimension)toDimension ofView:(ALView *)peerView withOffset:(CGFloat)offset +- (NSLayoutConstraint *)autoMatchDimension:(ALDimension)dimension toDimension:(ALDimension)toDimension ofView:(ALView *)otherView withOffset:(CGFloat)offset { - return [self autoMatchDimension:dimension toDimension:toDimension ofView:peerView withOffset:offset relation:NSLayoutRelationEqual]; + return [self autoMatchDimension:dimension toDimension:toDimension ofView:otherView withOffset:offset relation:NSLayoutRelationEqual]; } /** Matches a dimension of the view to a given dimension of another view with an offset as a maximum or minimum. @param dimension The dimension of this view to pin. - @param toDimension The dimension of the peer view to pin to. - @param peerView The peer view to match to. Must be in the same view hierarchy as this view. - @param offset The offset between the dimension of this view and the dimension of the peer view. + @param toDimension The dimension of the other view to pin to. + @param otherView The other view to match to. Must be in the same view hierarchy as this view. + @param offset The offset between the dimension of this view and the dimension of the other view. @param relation Whether the offset should be at least, at most, or exactly equal to the given value. @return The constraint added. */ -- (NSLayoutConstraint *)autoMatchDimension:(ALDimension)dimension toDimension:(ALDimension)toDimension ofView:(ALView *)peerView withOffset:(CGFloat)offset relation:(NSLayoutRelation)relation +- (NSLayoutConstraint *)autoMatchDimension:(ALDimension)dimension toDimension:(ALDimension)toDimension ofView:(ALView *)otherView withOffset:(CGFloat)offset relation:(NSLayoutRelation)relation { - self.translatesAutoresizingMaskIntoConstraints = NO; - NSLayoutAttribute attribute = [ALView al_attributeForDimension:dimension]; - NSLayoutAttribute toAttribute = [ALView al_attributeForDimension:toDimension]; - NSLayoutConstraint *constraint = [NSLayoutConstraint constraintWithItem:self attribute:attribute relatedBy:relation toItem:peerView attribute:toAttribute multiplier:1.0f constant:offset]; - [constraint autoInstall]; - return constraint; + return [self autoConstrainAttribute:(ALAttribute)dimension toAttribute:(ALAttribute)toDimension ofView:otherView withOffset:offset relation:relation]; } /** Matches a dimension of the view to a multiple of a given dimension of another view. @param dimension The dimension of this view to pin. - @param toDimension The dimension of the peer view to pin to. - @param peerView The peer view to match to. Must be in the same view hierarchy as this view. - @param multiplier The multiple of the peer view's given dimension that this view's given dimension should be. + @param toDimension The dimension of the other view to pin to. + @param otherView The other view to match to. Must be in the same view hierarchy as this view. + @param multiplier The multiple of the other view's given dimension that this view's given dimension should be. @return The constraint added. */ -- (NSLayoutConstraint *)autoMatchDimension:(ALDimension)dimension toDimension:(ALDimension)toDimension ofView:(ALView *)peerView withMultiplier:(CGFloat)multiplier +- (NSLayoutConstraint *)autoMatchDimension:(ALDimension)dimension toDimension:(ALDimension)toDimension ofView:(ALView *)otherView withMultiplier:(CGFloat)multiplier { - return [self autoMatchDimension:dimension toDimension:toDimension ofView:peerView withMultiplier:multiplier relation:NSLayoutRelationEqual]; + return [self autoMatchDimension:dimension toDimension:toDimension ofView:otherView withMultiplier:multiplier relation:NSLayoutRelationEqual]; } /** Matches a dimension of the view to a multiple of a given dimension of another view as a maximum or minimum. @param dimension The dimension of this view to pin. - @param toDimension The dimension of the peer view to pin to. - @param peerView The peer view to match to. Must be in the same view hierarchy as this view. - @param multiplier The multiple of the peer view's given dimension that this view's given dimension should be. + @param toDimension The dimension of the other view to pin to. + @param otherView The other view to match to. Must be in the same view hierarchy as this view. + @param multiplier The multiple of the other view's given dimension that this view's given dimension should be. @param relation Whether the multiple should be at least, at most, or exactly equal to the given value. @return The constraint added. */ -- (NSLayoutConstraint *)autoMatchDimension:(ALDimension)dimension toDimension:(ALDimension)toDimension ofView:(ALView *)peerView withMultiplier:(CGFloat)multiplier relation:(NSLayoutRelation)relation +- (NSLayoutConstraint *)autoMatchDimension:(ALDimension)dimension toDimension:(ALDimension)toDimension ofView:(ALView *)otherView withMultiplier:(CGFloat)multiplier relation:(NSLayoutRelation)relation { - self.translatesAutoresizingMaskIntoConstraints = NO; - NSLayoutAttribute attribute = [ALView al_attributeForDimension:dimension]; - NSLayoutAttribute toAttribute = [ALView al_attributeForDimension:toDimension]; - NSLayoutConstraint *constraint = [NSLayoutConstraint constraintWithItem:self attribute:attribute relatedBy:relation toItem:peerView attribute:toAttribute multiplier:multiplier constant:0.0f]; - [constraint autoInstall]; - return constraint; + return [self autoConstrainAttribute:(ALAttribute)dimension toAttribute:(ALAttribute)toDimension ofView:otherView withMultiplier:multiplier relation:relation]; } @@ -533,8 +652,8 @@ - (NSLayoutConstraint *)autoSetDimension:(ALDimension)dimension toSize:(CGFloat) - (NSLayoutConstraint *)autoSetDimension:(ALDimension)dimension toSize:(CGFloat)size relation:(NSLayoutRelation)relation { self.translatesAutoresizingMaskIntoConstraints = NO; - NSLayoutAttribute attribute = [ALView al_attributeForDimension:dimension]; - NSLayoutConstraint *constraint = [NSLayoutConstraint constraintWithItem:self attribute:attribute relatedBy:relation toItem:nil attribute:NSLayoutAttributeNotAnAttribute multiplier:0.0f constant:size]; + NSLayoutAttribute layoutAttribute = [NSLayoutConstraint al_layoutAttributeForAttribute:(ALAttribute)dimension]; + NSLayoutConstraint *constraint = [NSLayoutConstraint constraintWithItem:self attribute:layoutAttribute relatedBy:relation toItem:nil attribute:NSLayoutAttributeNotAnAttribute multiplier:0.0 constant:size]; [constraint autoInstall]; return constraint; } @@ -544,40 +663,40 @@ - (NSLayoutConstraint *)autoSetDimension:(ALDimension)dimension toSize:(CGFloat) /** Sets the priority of content compression resistance for an axis. - NOTE: This method must only be called from within the block passed into the method +[autoSetPriority:forConstraints:] + NOTE: This method must be called from within the block passed into the method +[autoSetPriority:forConstraints:] @param axis The axis to set the content compression resistance priority for. */ - (void)autoSetContentCompressionResistancePriorityForAxis:(ALAxis)axis { - NSAssert(_al_isExecutingConstraintsBlock, @"%@ should only be called from within the block passed into the method +[autoSetPriority:forConstraints:]", NSStringFromSelector(_cmd)); - if (_al_isExecutingConstraintsBlock) { + NSAssert([ALView al_isExecutingPriorityConstraintsBlock], @"%@ should only be called from within the block passed into the method +[autoSetPriority:forConstraints:]", NSStringFromSelector(_cmd)); + if ([ALView al_isExecutingPriorityConstraintsBlock]) { self.translatesAutoresizingMaskIntoConstraints = NO; - ALLayoutConstraintAxis constraintAxis = [ALView al_constraintAxisForAxis:axis]; + ALLayoutConstraintAxis constraintAxis = [NSLayoutConstraint al_constraintAxisForAxis:axis]; #if TARGET_OS_IPHONE - [self setContentCompressionResistancePriority:_al_globalConstraintPriority forAxis:constraintAxis]; + [self setContentCompressionResistancePriority:[ALView al_currentGlobalConstraintPriority] forAxis:constraintAxis]; #else - [self setContentCompressionResistancePriority:_al_globalConstraintPriority forOrientation:constraintAxis]; + [self setContentCompressionResistancePriority:[ALView al_currentGlobalConstraintPriority] forOrientation:constraintAxis]; #endif /* TARGET_OS_IPHONE */ } } /** Sets the priority of content hugging for an axis. - NOTE: This method must only be called from within the block passed into the method +[autoSetPriority:forConstraints:] + NOTE: This method must be called from within the block passed into the method +[autoSetPriority:forConstraints:] @param axis The axis to set the content hugging priority for. */ - (void)autoSetContentHuggingPriorityForAxis:(ALAxis)axis { - NSAssert(_al_isExecutingConstraintsBlock, @"%@ should only be called from within the block passed into the method +[autoSetPriority:forConstraints:]", NSStringFromSelector(_cmd)); - if (_al_isExecutingConstraintsBlock) { + NSAssert([ALView al_isExecutingPriorityConstraintsBlock], @"%@ should only be called from within the block passed into the method +[autoSetPriority:forConstraints:]", NSStringFromSelector(_cmd)); + if ([ALView al_isExecutingPriorityConstraintsBlock]) { self.translatesAutoresizingMaskIntoConstraints = NO; - ALLayoutConstraintAxis constraintAxis = [ALView al_constraintAxisForAxis:axis]; + ALLayoutConstraintAxis constraintAxis = [NSLayoutConstraint al_constraintAxisForAxis:axis]; #if TARGET_OS_IPHONE - [self setContentHuggingPriority:_al_globalConstraintPriority forAxis:constraintAxis]; + [self setContentHuggingPriority:[ALView al_currentGlobalConstraintPriority] forAxis:constraintAxis]; #else - [self setContentHuggingPriority:_al_globalConstraintPriority forOrientation:constraintAxis]; + [self setContentHuggingPriority:[ALView al_currentGlobalConstraintPriority] forOrientation:constraintAxis]; #endif /* TARGET_OS_IPHONE */ } } @@ -586,87 +705,87 @@ - (void)autoSetContentHuggingPriorityForAxis:(ALAxis)axis #pragma mark Constrain Any Attributes /** - Constrains an attribute (any ALEdge, ALAxis, or ALDimension) of the view to a given attribute of another view. + Constrains an attribute of the view to a given attribute of another view. This method can be used to constrain different types of attributes across two views. - @param ALAttribute Any ALEdge, ALAxis, or ALDimension of this view to constrain. - @param toALAttribute Any ALEdge, ALAxis, or ALDimension of the peer view to constrain to. - @param peerView The peer view to constrain to. Must be in the same view hierarchy as this view. + @param attribute Any attribute of this view to constrain. + @param toAttribute Any attribute of the other view to constrain to. + @param otherView The other view to constrain to. Must be in the same view hierarchy as this view. @return The constraint added. */ -- (NSLayoutConstraint *)autoConstrainAttribute:(NSInteger)ALAttribute toAttribute:(NSInteger)toALAttribute ofView:(ALView *)peerView +- (NSLayoutConstraint *)autoConstrainAttribute:(ALAttribute)attribute toAttribute:(ALAttribute)toAttribute ofView:(ALView *)otherView { - return [self autoConstrainAttribute:ALAttribute toAttribute:toALAttribute ofView:peerView withOffset:0.0f]; + return [self autoConstrainAttribute:attribute toAttribute:toAttribute ofView:otherView withOffset:0.0]; } /** - Constrains an attribute (any ALEdge, ALAxis, or ALDimension) of the view to a given attribute of another view with an offset. + Constrains an attribute of the view to a given attribute of another view with an offset. This method can be used to constrain different types of attributes across two views. - @param ALAttribute Any ALEdge, ALAxis, or ALDimension of this view to constrain. - @param toALAttribute Any ALEdge, ALAxis, or ALDimension of the peer view to constrain to. - @param peerView The peer view to constrain to. Must be in the same view hierarchy as this view. - @param offset The offset between the attribute of this view and the attribute of the peer view. + @param attribute Any attribute of this view to constrain. + @param toAttribute Any attribute of the other view to constrain to. + @param otherView The other view to constrain to. Must be in the same view hierarchy as this view. + @param offset The offset between the attribute of this view and the attribute of the other view. @return The constraint added. */ -- (NSLayoutConstraint *)autoConstrainAttribute:(NSInteger)ALAttribute toAttribute:(NSInteger)toALAttribute ofView:(ALView *)peerView withOffset:(CGFloat)offset +- (NSLayoutConstraint *)autoConstrainAttribute:(ALAttribute)attribute toAttribute:(ALAttribute)toAttribute ofView:(ALView *)otherView withOffset:(CGFloat)offset { - return [self autoConstrainAttribute:ALAttribute toAttribute:toALAttribute ofView:peerView withOffset:offset relation:NSLayoutRelationEqual]; + return [self autoConstrainAttribute:attribute toAttribute:toAttribute ofView:otherView withOffset:offset relation:NSLayoutRelationEqual]; } /** - Constrains an attribute (any ALEdge, ALAxis, or ALDimension) of the view to a given attribute of another view with an offset as a maximum or minimum. + Constrains an attribute of the view to a given attribute of another view with an offset as a maximum or minimum. This method can be used to constrain different types of attributes across two views. - @param ALAttribute Any ALEdge, ALAxis, or ALDimension of this view to constrain. - @param toALAttribute Any ALEdge, ALAxis, or ALDimension of the peer view to constrain to. - @param peerView The peer view to constrain to. Must be in the same view hierarchy as this view. - @param offset The offset between the attribute of this view and the attribute of the peer view. + @param attribute Any attribute of this view to constrain. + @param toAttribute Any attribute of the other view to constrain to. + @param otherView The other view to constrain to. Must be in the same view hierarchy as this view. + @param offset The offset between the attribute of this view and the attribute of the other view. @param relation Whether the offset should be at least, at most, or exactly equal to the given value. @return The constraint added. */ -- (NSLayoutConstraint *)autoConstrainAttribute:(NSInteger)ALAttribute toAttribute:(NSInteger)toALAttribute ofView:(ALView *)peerView withOffset:(CGFloat)offset relation:(NSLayoutRelation)relation +- (NSLayoutConstraint *)autoConstrainAttribute:(ALAttribute)attribute toAttribute:(ALAttribute)toAttribute ofView:(ALView *)otherView withOffset:(CGFloat)offset relation:(NSLayoutRelation)relation { self.translatesAutoresizingMaskIntoConstraints = NO; - NSLayoutAttribute attribute = [ALView al_attributeForALAttribute:ALAttribute]; - NSLayoutAttribute toAttribute = [ALView al_attributeForALAttribute:toALAttribute]; - NSLayoutConstraint *constraint = [NSLayoutConstraint constraintWithItem:self attribute:attribute relatedBy:relation toItem:peerView attribute:toAttribute multiplier:1.0f constant:offset]; + NSLayoutAttribute layoutAttribute = [NSLayoutConstraint al_layoutAttributeForAttribute:attribute]; + NSLayoutAttribute toLayoutAttribute = [NSLayoutConstraint al_layoutAttributeForAttribute:toAttribute]; + NSLayoutConstraint *constraint = [NSLayoutConstraint constraintWithItem:self attribute:layoutAttribute relatedBy:relation toItem:otherView attribute:toLayoutAttribute multiplier:1.0 constant:offset]; [constraint autoInstall]; return constraint; } /** - Constrains an attribute (any ALEdge, ALAxis, or ALDimension) of the view to a given attribute of another view with a multiplier. + Constrains an attribute of the view to a given attribute of another view with a multiplier. This method can be used to constrain different types of attributes across two views. - @param ALAttribute Any ALEdge, ALAxis, or ALDimension of this view to constrain. - @param toALAttribute Any ALEdge, ALAxis, or ALDimension of the peer view to constrain to. - @param peerView The peer view to constrain to. Must be in the same view hierarchy as this view. - @param multiplier The multiplier between the attribute of this view and the attribute of the peer view. + @param attribute Any attribute of this view to constrain. + @param toAttribute Any attribute of the other view to constrain to. + @param otherView The other view to constrain to. Must be in the same view hierarchy as this view. + @param multiplier The multiplier between the attribute of this view and the attribute of the other view. @return The constraint added. */ -- (NSLayoutConstraint *)autoConstrainAttribute:(NSInteger)ALAttribute toAttribute:(NSInteger)toALAttribute ofView:(ALView *)peerView withMultiplier:(CGFloat)multiplier +- (NSLayoutConstraint *)autoConstrainAttribute:(ALAttribute)attribute toAttribute:(ALAttribute)toAttribute ofView:(ALView *)otherView withMultiplier:(CGFloat)multiplier { - return [self autoConstrainAttribute:ALAttribute toAttribute:toALAttribute ofView:peerView withMultiplier:multiplier relation:NSLayoutRelationEqual]; + return [self autoConstrainAttribute:attribute toAttribute:toAttribute ofView:otherView withMultiplier:multiplier relation:NSLayoutRelationEqual]; } /** - Constrains an attribute (any ALEdge, ALAxis, or ALDimension) of the view to a given attribute of another view with a multiplier as a maximum or minimum. + Constrains an attribute of the view to a given attribute of another view with a multiplier as a maximum or minimum. This method can be used to constrain different types of attributes across two views. - @param ALAttribute Any ALEdge, ALAxis, or ALDimension of this view to constrain. - @param toALAttribute Any ALEdge, ALAxis, or ALDimension of the peer view to constrain to. - @param peerView The peer view to constrain to. Must be in the same view hierarchy as this view. - @param multiplier The multiplier between the attribute of this view and the attribute of the peer view. + @param attribute Any attribute of this view to constrain. + @param toAttribute Any attribute of the other view to constrain to. + @param otherView The other view to constrain to. Must be in the same view hierarchy as this view. + @param multiplier The multiplier between the attribute of this view and the attribute of the other view. @param relation Whether the multiplier should be at least, at most, or exactly equal to the given value. @return The constraint added. */ -- (NSLayoutConstraint *)autoConstrainAttribute:(NSInteger)ALAttribute toAttribute:(NSInteger)toALAttribute ofView:(ALView *)peerView withMultiplier:(CGFloat)multiplier relation:(NSLayoutRelation)relation +- (NSLayoutConstraint *)autoConstrainAttribute:(ALAttribute)attribute toAttribute:(ALAttribute)toAttribute ofView:(ALView *)otherView withMultiplier:(CGFloat)multiplier relation:(NSLayoutRelation)relation { self.translatesAutoresizingMaskIntoConstraints = NO; - NSLayoutAttribute attribute = [ALView al_attributeForALAttribute:ALAttribute]; - NSLayoutAttribute toAttribute = [ALView al_attributeForALAttribute:toALAttribute]; - NSLayoutConstraint *constraint = [NSLayoutConstraint constraintWithItem:self attribute:attribute relatedBy:relation toItem:peerView attribute:toAttribute multiplier:multiplier constant:0.0f]; + NSLayoutAttribute layoutAttribute = [NSLayoutConstraint al_layoutAttributeForAttribute:attribute]; + NSLayoutAttribute toLayoutAttribute = [NSLayoutConstraint al_layoutAttributeForAttribute:toAttribute]; + NSLayoutConstraint *constraint = [NSLayoutConstraint constraintWithItem:self attribute:layoutAttribute relatedBy:relation toItem:otherView attribute:toLayoutAttribute multiplier:multiplier constant:0.0]; [constraint autoInstall]; return constraint; } @@ -687,13 +806,19 @@ - (NSLayoutConstraint *)autoConstrainAttribute:(NSInteger)ALAttribute toAttribut */ - (NSLayoutConstraint *)autoPinToTopLayoutGuideOfViewController:(UIViewController *)viewController withInset:(CGFloat)inset { - if (floor(NSFoundationVersionNumber) <= NSFoundationVersionNumber_iOS_6_1) { - return [self autoPinEdge:ALEdgeTop toEdge:ALEdgeTop ofView:viewController.view withOffset:inset]; - } else { + return [self autoPinToTopLayoutGuideOfViewController:viewController withInset:inset relation:NSLayoutRelationEqual]; +} + +- (NSLayoutConstraint *)autoPinToTopLayoutGuideOfViewController:(UIViewController *)viewController withInset:(CGFloat)inset relation:(NSLayoutRelation)relation +{ + if (__PureLayout_MinSysVer_iOS_7_0) { self.translatesAutoresizingMaskIntoConstraints = NO; - NSLayoutConstraint *constraint = [NSLayoutConstraint constraintWithItem:self attribute:NSLayoutAttributeTop relatedBy:NSLayoutRelationEqual toItem:viewController.topLayoutGuide attribute:NSLayoutAttributeBottom multiplier:1.0f constant:inset]; - [viewController.view al_addConstraintUsingGlobalPriority:constraint]; + NSLayoutConstraint *constraint = [NSLayoutConstraint constraintWithItem:self attribute:NSLayoutAttributeTop relatedBy:relation toItem:viewController.topLayoutGuide attribute:NSLayoutAttributeBottom multiplier:1.0 constant:inset]; + [viewController.view al_addConstraint:constraint]; // Can't use autoInstall because the layout guide is not a view return constraint; + } else { + // iOS 6 fallback + return [self autoPinEdge:ALEdgeTop toEdge:ALEdgeTop ofView:viewController.view withOffset:inset relation:relation]; } } @@ -708,205 +833,160 @@ - (NSLayoutConstraint *)autoPinToTopLayoutGuideOfViewController:(UIViewControlle */ - (NSLayoutConstraint *)autoPinToBottomLayoutGuideOfViewController:(UIViewController *)viewController withInset:(CGFloat)inset { - if (floor(NSFoundationVersionNumber) <= NSFoundationVersionNumber_iOS_6_1) { - return [self autoPinEdge:ALEdgeBottom toEdge:ALEdgeBottom ofView:viewController.view withOffset:-inset]; - } else { + return [self autoPinToBottomLayoutGuideOfViewController:viewController withInset:inset relation:NSLayoutRelationEqual]; +} + +- (NSLayoutConstraint *)autoPinToBottomLayoutGuideOfViewController:(UIViewController *)viewController withInset:(CGFloat)inset relation:(NSLayoutRelation)relation +{ + // The bottom inset (and relation, if an inequality) is inverted to become an offset + inset = -inset; + if (relation == NSLayoutRelationLessThanOrEqual) { + relation = NSLayoutRelationGreaterThanOrEqual; + } else if (relation == NSLayoutRelationGreaterThanOrEqual) { + relation = NSLayoutRelationLessThanOrEqual; + } + if (__PureLayout_MinSysVer_iOS_7_0) { self.translatesAutoresizingMaskIntoConstraints = NO; - NSLayoutConstraint *constraint = [NSLayoutConstraint constraintWithItem:self attribute:NSLayoutAttributeBottom relatedBy:NSLayoutRelationEqual toItem:viewController.bottomLayoutGuide attribute:NSLayoutAttributeTop multiplier:1.0f constant:-inset]; - [viewController.view al_addConstraintUsingGlobalPriority:constraint]; + NSLayoutConstraint *constraint = [NSLayoutConstraint constraintWithItem:self attribute:NSLayoutAttributeBottom relatedBy:relation toItem:viewController.bottomLayoutGuide attribute:NSLayoutAttributeTop multiplier:1.0 constant:inset]; + [viewController.view al_addConstraint:constraint]; // Can't use autoInstall because the layout guide is not a view return constraint; + } else { + // iOS 6 fallback + return [self autoPinEdge:ALEdgeBottom toEdge:ALEdgeBottom ofView:viewController.view withOffset:inset relation:relation]; } } #endif /* TARGET_OS_IPHONE */ -#pragma mark Internal Helper Methods +#pragma mark Deprecated Methods /** - Adds the given constraint to this view after setting the constraint's priority to the global constraint priority. - - This method is the only one that calls the SDK addConstraint: method directly; all other instances in this category - should use this method to add constraints so that the global priority is correctly set on constraints. - - @param constraint The constraint to set the global priority on and then add to this view. + DEPRECATED as of PureLayout v2.0.0. Retain a reference to and remove specific constraints instead, or recreate the view(s) entirely to remove all constraints. + Removes all explicit constraints that affect the view. + WARNING: Apple's constraint solver is not optimized for large-scale constraint removal; you may encounter major performance issues after using this method. + It is not recommended to use this method to "reset" a view for reuse in a different way with new constraints. Create a new view instead. + NOTE: This method preserves implicit constraints, such as intrinsic content size constraints, which you usually do not want to remove. */ -- (void)al_addConstraintUsingGlobalPriority:(NSLayoutConstraint *)constraint +- (void)autoRemoveConstraintsAffectingView { - constraint.priority = _al_globalConstraintPriority; - [self addConstraint:constraint]; + [self autoRemoveConstraintsAffectingViewIncludingImplicitConstraints:NO]; } /** - Returns the corresponding NSLayoutAttribute for the given ALEdge. + DEPRECATED as of PureLayout v2.0.0. Retain a reference to and remove specific constraints instead, or recreate the view(s) entirely to remove all constraints. + Removes all constraints that affect the view, optionally including implicit constraints. + WARNING: Apple's constraint solver is not optimized for large-scale constraint removal; you may encounter major performance issues after using this method. + It is not recommended to use this method to "reset" a view for reuse in a different way with new constraints. Create a new view instead. + NOTE: Implicit constraints are auto-generated lower priority constraints (such as those that attempt to keep a view at + its intrinsic content size by hugging its content & resisting compression), and you usually do not want to remove these. - @return The layout attribute for the given edge. + @param shouldRemoveImplicitConstraints Whether implicit constraints should be removed or skipped. */ -+ (NSLayoutAttribute)al_attributeForEdge:(ALEdge)edge +- (void)autoRemoveConstraintsAffectingViewIncludingImplicitConstraints:(BOOL)shouldRemoveImplicitConstraints { - NSLayoutAttribute attribute = NSLayoutAttributeNotAnAttribute; - switch (edge) { - case ALEdgeLeft: - attribute = NSLayoutAttributeLeft; - break; - case ALEdgeRight: - attribute = NSLayoutAttributeRight; - break; - case ALEdgeTop: - attribute = NSLayoutAttributeTop; - break; - case ALEdgeBottom: - attribute = NSLayoutAttributeBottom; - break; - case ALEdgeLeading: - attribute = NSLayoutAttributeLeading; - break; - case ALEdgeTrailing: - attribute = NSLayoutAttributeTrailing; - break; - default: - NSAssert(nil, @"Not a valid ALEdge."); - break; - } - return attribute; + NSMutableArray *constraintsToRemove = [NSMutableArray new]; + ALView *startView = self; + do { + for (NSLayoutConstraint *constraint in startView.constraints) { + BOOL isImplicitConstraint = [NSStringFromClass([constraint class]) isEqualToString:@"NSContentSizeLayoutConstraint"]; + if (shouldRemoveImplicitConstraints || !isImplicitConstraint) { + if (constraint.firstItem == self || constraint.secondItem == self) { + [constraintsToRemove addObject:constraint]; + } + } + } + startView = startView.superview; + } while (startView); + [constraintsToRemove autoRemoveConstraints]; } /** - Returns the corresponding NSLayoutAttribute for the given ALAxis. - - @return The layout attribute for the given axis. + DEPRECATED as of PureLayout v2.0.0. Retain a reference to and remove specific constraints instead, or recreate the view(s) entirely to remove all constraints. + Recursively removes all explicit constraints that affect the view and its subviews. + WARNING: Apple's constraint solver is not optimized for large-scale constraint removal; you may encounter major performance issues after using this method. + It is not recommended to use this method to "reset" views for reuse in a different way with new constraints. Create a new view instead. + NOTE: This method preserves implicit constraints, such as intrinsic content size constraints, which you usually do not want to remove. */ -+ (NSLayoutAttribute)al_attributeForAxis:(ALAxis)axis +- (void)autoRemoveConstraintsAffectingViewAndSubviews { - NSLayoutAttribute attribute = NSLayoutAttributeNotAnAttribute; - switch (axis) { - case ALAxisVertical: - attribute = NSLayoutAttributeCenterX; - break; - case ALAxisHorizontal: - attribute = NSLayoutAttributeCenterY; - break; - case ALAxisBaseline: - attribute = NSLayoutAttributeBaseline; - break; - default: - NSAssert(nil, @"Not a valid ALAxis."); - break; - } - return attribute; + [self autoRemoveConstraintsAffectingViewAndSubviewsIncludingImplicitConstraints:NO]; } /** - Returns the corresponding NSLayoutAttribute for the given ALDimension. + DEPRECATED as of PureLayout v2.0.0. Retain a reference to and remove specific constraints instead, or recreate the view(s) entirely to remove all constraints. + Recursively removes all constraints that affect the view and its subviews, optionally including implicit constraints. + WARNING: Apple's constraint solver is not optimized for large-scale constraint removal; you may encounter major performance issues after using this method. + It is not recommended to use this method to "reset" views for reuse in a different way with new constraints. Create a new view instead. + NOTE: Implicit constraints are auto-generated lower priority constraints (such as those that attempt to keep a view at + its intrinsic content size by hugging its content & resisting compression), and you usually do not want to remove these. - @return The layout attribute for the given dimension. + @param shouldRemoveImplicitConstraints Whether implicit constraints should be removed or skipped. */ -+ (NSLayoutAttribute)al_attributeForDimension:(ALDimension)dimension +- (void)autoRemoveConstraintsAffectingViewAndSubviewsIncludingImplicitConstraints:(BOOL)shouldRemoveImplicitConstraints { - NSLayoutAttribute attribute = NSLayoutAttributeNotAnAttribute; - switch (dimension) { - case ALDimensionWidth: - attribute = NSLayoutAttributeWidth; - break; - case ALDimensionHeight: - attribute = NSLayoutAttributeHeight; - break; - default: - NSAssert(nil, @"Not a valid ALDimension."); - break; + [self autoRemoveConstraintsAffectingViewIncludingImplicitConstraints:shouldRemoveImplicitConstraints]; + for (ALView *subview in self.subviews) { + [subview autoRemoveConstraintsAffectingViewAndSubviewsIncludingImplicitConstraints:shouldRemoveImplicitConstraints]; } - return attribute; } + +#pragma mark Internal Methods + /** - Returns the corresponding NSLayoutAttribute for the given ALAttribute. + Applies the global constraint priority and identifier to the given constraint. + This should be done before installing all constraints. - @return The layout attribute for the given ALAttribute. + @param constraint The constraint to set the global priority and identifier on. */ -+ (NSLayoutAttribute)al_attributeForALAttribute:(NSInteger)ALAttribute ++ (void)al_applyGlobalStateToConstraint:(NSLayoutConstraint *)constraint { - NSLayoutAttribute attribute = NSLayoutAttributeNotAnAttribute; - switch (ALAttribute) { - case ALEdgeLeft: - attribute = NSLayoutAttributeLeft; - break; - case ALEdgeRight: - attribute = NSLayoutAttributeRight; - break; - case ALEdgeTop: - attribute = NSLayoutAttributeTop; - break; - case ALEdgeBottom: - attribute = NSLayoutAttributeBottom; - break; - case ALEdgeLeading: - attribute = NSLayoutAttributeLeading; - break; - case ALEdgeTrailing: - attribute = NSLayoutAttributeTrailing; - break; - case ALDimensionWidth: - attribute = NSLayoutAttributeWidth; - break; - case ALDimensionHeight: - attribute = NSLayoutAttributeHeight; - break; - case ALAxisVertical: - attribute = NSLayoutAttributeCenterX; - break; - case ALAxisHorizontal: - attribute = NSLayoutAttributeCenterY; - break; - case ALAxisBaseline: - attribute = NSLayoutAttributeBaseline; - break; - default: - NSAssert(nil, @"Not a valid ALAttribute."); - break; + if ([ALView al_isExecutingPriorityConstraintsBlock]) { + constraint.priority = [ALView al_currentGlobalConstraintPriority]; } - return attribute; +#if __PureLayout_MinBaseSDK_iOS_8_0 + NSString *globalConstraintIdentifier = [ALView al_currentGlobalConstraintIdentifier]; + if (globalConstraintIdentifier) { + [constraint autoIdentify:globalConstraintIdentifier]; + } +#endif /* __PureLayout_MinBaseSDK_iOS_8_0 */ } /** - Returns the corresponding ALLayoutConstraintAxis for the given ALAxis. + Adds the given constraint to this view after applying the global state to the constraint. + NOTE: This method is compatible with all versions of iOS, and should be used for older versions before the active + property on NSLayoutConstraint was introduced. + + This method should be the only one that calls the UIView/NSView addConstraint: method directly. - @return The constraint axis for the given axis. + @param constraint The constraint to set the global priority on and then add to this view. */ -+ (ALLayoutConstraintAxis)al_constraintAxisForAxis:(ALAxis)axis +- (void)al_addConstraint:(NSLayoutConstraint *)constraint { - ALLayoutConstraintAxis constraintAxis; - switch (axis) { - case ALAxisVertical: - constraintAxis = ALLayoutConstraintAxisVertical; - break; - case ALAxisHorizontal: - case ALAxisBaseline: - constraintAxis = ALLayoutConstraintAxisHorizontal; - break; - default: - NSAssert(nil, @"Not a valid ALAxis."); - break; + [ALView al_applyGlobalStateToConstraint:constraint]; + if (![ALView al_preventAutomaticConstraintInstallation]) { + [self addConstraint:constraint]; } - return constraintAxis; } /** - Returns the common superview for this view and the given peer view. - Raises an exception if this view and the peer view do not share a common superview. + Returns the common superview for this view and the given other view. + Raises an exception if this view and the other view do not share a common superview. @return The common superview for the two views. */ -- (ALView *)al_commonSuperviewWithView:(ALView *)peerView +- (ALView *)al_commonSuperviewWithView:(ALView *)otherView { ALView *commonSuperview = nil; ALView *startView = self; do { #if TARGET_OS_IPHONE - if ([peerView isDescendantOfView:startView]) { + if ([otherView isDescendantOfView:startView]) { commonSuperview = startView; } #else - if ([peerView isDescendantOf:startView]) { + if ([otherView isDescendantOf:startView]) { commonSuperview = startView; } #endif /* TARGET_OS_IPHONE */ @@ -917,52 +997,59 @@ - (ALView *)al_commonSuperviewWithView:(ALView *)peerView } /** - Aligns this view to a peer view with an alignment option. + Aligns this view to another view with an alignment attribute. - @param peerView The peer view to align to. - @param alignment The alignment option to apply to the two views. - @param axis The axis along which the views are distributed, used to validate the alignment option. + @param attribute The attribute to use to align the two views. + @param otherView The other view to align to. + @param axis The axis along which the views are distributed, used to validate the alignment attribute. @return The constraint added. */ -- (NSLayoutConstraint *)al_alignToView:(ALView *)peerView withOption:(NSLayoutFormatOptions)alignment forAxis:(ALAxis)axis +- (NSLayoutConstraint *)al_alignAttribute:(ALAttribute)attribute toView:(ALView *)otherView forAxis:(ALAxis)axis { NSLayoutConstraint *constraint = nil; - switch (alignment) { - case NSLayoutFormatAlignAllCenterX: - NSAssert(axis == ALAxisVertical, @"Cannot align views that are distributed horizontally with NSLayoutFormatAlignAllCenterX."); - constraint = [self autoAlignAxis:ALAxisVertical toSameAxisOfView:peerView]; + switch (attribute) { + case ALAttributeVertical: + NSAssert(axis == ALAxisVertical, @"Cannot align views that are distributed horizontally with ALAttributeVertical."); + constraint = [self autoAlignAxis:ALAxisVertical toSameAxisOfView:otherView]; + break; + case ALAttributeHorizontal: + NSAssert(axis != ALAxisVertical, @"Cannot align views that are distributed vertically with ALAttributeHorizontal."); + constraint = [self autoAlignAxis:ALAxisHorizontal toSameAxisOfView:otherView]; break; - case NSLayoutFormatAlignAllCenterY: - NSAssert(axis != ALAxisVertical, @"Cannot align views that are distributed vertically with NSLayoutFormatAlignAllCenterY."); - constraint = [self autoAlignAxis:ALAxisHorizontal toSameAxisOfView:peerView]; + case ALAttributeBaseline: // same value as ALAttributeLastBaseline + NSAssert(axis != ALAxisVertical, @"Cannot align views that are distributed vertically with ALAttributeBaseline."); + constraint = [self autoAlignAxis:ALAxisBaseline toSameAxisOfView:otherView]; break; - case NSLayoutFormatAlignAllBaseline: - NSAssert(axis != ALAxisVertical, @"Cannot align views that are distributed vertically with NSLayoutFormatAlignAllBaseline."); - constraint = [self autoAlignAxis:ALAxisBaseline toSameAxisOfView:peerView]; +#if __PureLayout_MinBaseSDK_iOS_8_0 + case ALAttributeFirstBaseline: + NSAssert(__PureLayout_MinSysVer_iOS_8_0, @"ALAttributeFirstBaseline is only supported on iOS 8.0 or higher."); + NSAssert(axis != ALAxisVertical, @"Cannot align views that are distributed vertically with ALAttributeFirstBaseline."); + constraint = [self autoAlignAxis:ALAxisFirstBaseline toSameAxisOfView:otherView]; break; - case NSLayoutFormatAlignAllTop: - NSAssert(axis != ALAxisVertical, @"Cannot align views that are distributed vertically with NSLayoutFormatAlignAllTop."); - constraint = [self autoPinEdge:ALEdgeTop toEdge:ALEdgeTop ofView:peerView]; +#endif /* __PureLayout_MinBaseSDK_iOS_8_0 */ + case ALAttributeTop: + NSAssert(axis != ALAxisVertical, @"Cannot align views that are distributed vertically with ALAttributeTop."); + constraint = [self autoPinEdge:ALEdgeTop toEdge:ALEdgeTop ofView:otherView]; break; - case NSLayoutFormatAlignAllLeft: - NSAssert(axis == ALAxisVertical, @"Cannot align views that are distributed horizontally with NSLayoutFormatAlignAllLeft."); - constraint = [self autoPinEdge:ALEdgeLeft toEdge:ALEdgeLeft ofView:peerView]; + case ALAttributeLeft: + NSAssert(axis == ALAxisVertical, @"Cannot align views that are distributed horizontally with ALAttributeLeft."); + constraint = [self autoPinEdge:ALEdgeLeft toEdge:ALEdgeLeft ofView:otherView]; break; - case NSLayoutFormatAlignAllBottom: - NSAssert(axis != ALAxisVertical, @"Cannot align views that are distributed vertically with NSLayoutFormatAlignAllBottom."); - constraint = [self autoPinEdge:ALEdgeBottom toEdge:ALEdgeBottom ofView:peerView]; + case ALAttributeBottom: + NSAssert(axis != ALAxisVertical, @"Cannot align views that are distributed vertically with ALAttributeBottom."); + constraint = [self autoPinEdge:ALEdgeBottom toEdge:ALEdgeBottom ofView:otherView]; break; - case NSLayoutFormatAlignAllRight: - NSAssert(axis == ALAxisVertical, @"Cannot align views that are distributed horizontally with NSLayoutFormatAlignAllRight."); - constraint = [self autoPinEdge:ALEdgeRight toEdge:ALEdgeRight ofView:peerView]; + case ALAttributeRight: + NSAssert(axis == ALAxisVertical, @"Cannot align views that are distributed horizontally with ALAttributeRight."); + constraint = [self autoPinEdge:ALEdgeRight toEdge:ALEdgeRight ofView:otherView]; break; - case NSLayoutFormatAlignAllLeading: - NSAssert(axis == ALAxisVertical, @"Cannot align views that are distributed horizontally with NSLayoutFormatAlignAllLeading."); - constraint = [self autoPinEdge:ALEdgeLeading toEdge:ALEdgeLeading ofView:peerView]; + case ALAttributeLeading: + NSAssert(axis == ALAxisVertical, @"Cannot align views that are distributed horizontally with ALAttributeLeading."); + constraint = [self autoPinEdge:ALEdgeLeading toEdge:ALEdgeLeading ofView:otherView]; break; - case NSLayoutFormatAlignAllTrailing: - NSAssert(axis == ALAxisVertical, @"Cannot align views that are distributed horizontally with NSLayoutFormatAlignAllTrailing."); - constraint = [self autoPinEdge:ALEdgeTrailing toEdge:ALEdgeTrailing ofView:peerView]; + case ALAttributeTrailing: + NSAssert(axis == ALAxisVertical, @"Cannot align views that are distributed horizontally with ALAttributeTrailing."); + constraint = [self autoPinEdge:ALEdgeTrailing toEdge:ALEdgeTrailing ofView:otherView]; break; default: NSAssert(nil, @"Unsupported alignment option."); diff --git a/TableViewCellWithAutoLayout/PureLayout/NSArray+PureLayout.h b/TableViewCellWithAutoLayout/PureLayout/NSArray+PureLayout.h index 307bb52..74d4c22 100755 --- a/TableViewCellWithAutoLayout/PureLayout/NSArray+PureLayout.h +++ b/TableViewCellWithAutoLayout/PureLayout/NSArray+PureLayout.h @@ -1,6 +1,6 @@ // // NSArray+PureLayout.h -// v1.1.0 +// v2.0.1 // https://github.com/smileyborg/PureLayout // // Copyright (c) 2012 Richard Turton @@ -33,12 +33,30 @@ #pragma mark - NSArray+PureLayout /** - A category on NSArray that provides a simple yet powerful interface for applying constraints to groups of views. + A category on NSArray that provides a simple yet powerful interface to: + - Manage an array of Auto Layout constraints + - Apply constraints to an array of views */ @interface NSArray (PureLayout) -#pragma mark Constrain Multiple Views +#pragma mark Array of Constraints + +/** Activates the constraints in this array. */ +- (void)autoInstallConstraints; + +/** Deactivates the constraints in this array. */ +- (void)autoRemoveConstraints; + +#if __PureLayout_MinBaseSDK_iOS_8_0 + +/** Sets the string as the identifier for the constraints in this array. Available in iOS 7.0 and OS X 10.9 and later. */ +- (instancetype)autoIdentifyConstraints:(NSString *)identifer; + +#endif /* __PureLayout_MinBaseSDK_iOS_8_0 */ + + +#pragma mark Array of Views /** Aligns views in this array to one another along a given edge. */ - (NSArray *)autoAlignViewsToEdge:(ALEdge)edge; @@ -53,21 +71,34 @@ - (NSArray *)autoSetViewsDimension:(ALDimension)dimension toSize:(CGFloat)size; -#pragma mark Distribute Multiple Views - /** Distributes the views in this array equally along the selected axis in their superview. Views will be the same size (variable) in the dimension along the axis and will have spacing (fixed) between them. */ -- (NSArray *)autoDistributeViewsAlongAxis:(ALAxis)axis withFixedSpacing:(CGFloat)spacing alignment:(NSLayoutFormatOptions)alignment; +- (NSArray *)autoDistributeViewsAlongAxis:(ALAxis)axis + alignedTo:(ALAttribute)alignment + withFixedSpacing:(CGFloat)spacing; /** Distributes the views in this array equally along the selected axis in their superview. Views will be the same size (variable) in the dimension along the axis and will have spacing (fixed) between them, with optional insets from the first and last views to their superview. */ -- (NSArray *)autoDistributeViewsAlongAxis:(ALAxis)axis withFixedSpacing:(CGFloat)spacing insetSpacing:(BOOL)shouldSpaceInsets alignment:(NSLayoutFormatOptions)alignment; +- (NSArray *)autoDistributeViewsAlongAxis:(ALAxis)axis + alignedTo:(ALAttribute)alignment + withFixedSpacing:(CGFloat)spacing + insetSpacing:(BOOL)shouldSpaceInsets; /** Distributes the views in this array equally along the selected axis in their superview. Views will have spacing (fixed) between them, with optional insets from the first and last views to their superview, and optionally constrained to the same size in the dimension along the axis. */ -- (NSArray *)autoDistributeViewsAlongAxis:(ALAxis)axis withFixedSpacing:(CGFloat)spacing insetSpacing:(BOOL)shouldSpaceInsets matchedSizes:(BOOL)shouldMatchSizes alignment:(NSLayoutFormatOptions)alignment; +- (NSArray *)autoDistributeViewsAlongAxis:(ALAxis)axis + alignedTo:(ALAttribute)alignment + withFixedSpacing:(CGFloat)spacing + insetSpacing:(BOOL)shouldSpaceInsets + matchedSizes:(BOOL)shouldMatchSizes; + /** Distributes the views in this array equally along the selected axis in their superview. Views will be the same size (fixed) in the dimension along the axis and will have spacing (variable) between them. */ -- (NSArray *)autoDistributeViewsAlongAxis:(ALAxis)axis withFixedSize:(CGFloat)size alignment:(NSLayoutFormatOptions)alignment; +- (NSArray *)autoDistributeViewsAlongAxis:(ALAxis)axis + alignedTo:(ALAttribute)alignment + withFixedSize:(CGFloat)size; /** Distributes the views in this array equally along the selected axis in their superview. Views will be the same size (fixed) in the dimension along the axis and will have spacing (variable) between them, with optional insets from the first and last views to their superview. */ -- (NSArray *)autoDistributeViewsAlongAxis:(ALAxis)axis withFixedSize:(CGFloat)size insetSpacing:(BOOL)shouldSpaceInsets alignment:(NSLayoutFormatOptions)alignment; +- (NSArray *)autoDistributeViewsAlongAxis:(ALAxis)axis + alignedTo:(ALAttribute)alignment + withFixedSize:(CGFloat)size + insetSpacing:(BOOL)shouldSpaceInsets; @end diff --git a/TableViewCellWithAutoLayout/PureLayout/NSArray+PureLayout.m b/TableViewCellWithAutoLayout/PureLayout/NSArray+PureLayout.m index 4c8cc8f..d2178d6 100755 --- a/TableViewCellWithAutoLayout/PureLayout/NSArray+PureLayout.m +++ b/TableViewCellWithAutoLayout/PureLayout/NSArray+PureLayout.m @@ -1,6 +1,6 @@ // // NSArray+PureLayout.m -// v1.1.0 +// v2.0.1 // https://github.com/smileyborg/PureLayout // // Copyright (c) 2012 Richard Turton @@ -38,7 +38,56 @@ @implementation NSArray (PureLayout) -#pragma mark Constrain Multiple Views +#pragma mark Array of Constraints + +/** + Activates the constraints in this array. + */ +- (void)autoInstallConstraints +{ + for (id object in self) { + if ([object isKindOfClass:[NSLayoutConstraint class]]) { + [((NSLayoutConstraint *)object) autoInstall]; + } + } +} + +/** + Deactivates the constraints in this array. + */ +- (void)autoRemoveConstraints +{ + for (id object in self) { + if ([object isKindOfClass:[NSLayoutConstraint class]]) { + [((NSLayoutConstraint *)object) autoRemove]; + } + } +} + +#if __PureLayout_MinBaseSDK_iOS_8_0 + +/** + Sets the string as the identifier for the constraints in this array. Available in iOS 7.0 and OS X 10.9 and later. + The identifer will be printed along with each constraint's description. + This is helpful to document the constraints' purpose and aid in debugging. + + @param identifier A string used to identify the constraints in this array. + @return This array. + */ +- (instancetype)autoIdentifyConstraints:(NSString *)identifer +{ + for (id object in self) { + if ([object isKindOfClass:[NSLayoutConstraint class]]) { + [((NSLayoutConstraint *)object) autoIdentify:identifer]; + } + } + return self; +} + +#endif /* __PureLayout_MinBaseSDK_iOS_8_0 */ + + +#pragma mark Array of Views /** Aligns views in this array to one another along a given edge. @@ -138,21 +187,24 @@ - (NSArray *)autoSetViewsDimension:(ALDimension)dimension toSize:(CGFloat)size } -#pragma mark Distribute Multiple Views - /** Distributes the views in this array equally along the selected axis in their superview. Views will be the same size (variable) in the dimension along the axis and will have spacing (fixed) between them, including from the first and last views to their superview. - @param axis The axis along which to distribute the subviews. + @param axis The axis along which to distribute the views. + @param alignment The attribute to use to align all the views to one another. @param spacing The fixed amount of spacing between each subview, before the first subview and after the last subview. - @param alignment The way in which the subviews will be aligned. @return An array of constraints added. */ -- (NSArray *)autoDistributeViewsAlongAxis:(ALAxis)axis withFixedSpacing:(CGFloat)spacing alignment:(NSLayoutFormatOptions)alignment +- (NSArray *)autoDistributeViewsAlongAxis:(ALAxis)axis + alignedTo:(ALAttribute)alignment + withFixedSpacing:(CGFloat)spacing { - return [self autoDistributeViewsAlongAxis:axis withFixedSpacing:spacing insetSpacing:YES alignment:alignment]; + return [self autoDistributeViewsAlongAxis:axis + alignedTo:alignment + withFixedSpacing:spacing + insetSpacing:YES]; } /** @@ -160,15 +212,22 @@ - (NSArray *)autoDistributeViewsAlongAxis:(ALAxis)axis withFixedSpacing:(CGFloat Views will be the same size (variable) in the dimension along the axis and will have spacing (fixed) between them. The first and last views can optionally be inset from their superview by the same amount of spacing as between views. - @param axis The axis along which to distribute the subviews. + @param axis The axis along which to distribute the views. + @param alignment The attribute to use to align all the views to one another. @param spacing The fixed amount of spacing between each subview. @param shouldSpaceInsets Whether the first and last views should be equally inset from their superview. - @param alignment The way in which the subviews will be aligned. @return An array of constraints added. */ -- (NSArray *)autoDistributeViewsAlongAxis:(ALAxis)axis withFixedSpacing:(CGFloat)spacing insetSpacing:(BOOL)shouldSpaceInsets alignment:(NSLayoutFormatOptions)alignment +- (NSArray *)autoDistributeViewsAlongAxis:(ALAxis)axis + alignedTo:(ALAttribute)alignment + withFixedSpacing:(CGFloat)spacing + insetSpacing:(BOOL)shouldSpaceInsets { - return [self autoDistributeViewsAlongAxis:axis withFixedSpacing:spacing insetSpacing:shouldSpaceInsets matchedSizes:YES alignment:alignment]; + return [self autoDistributeViewsAlongAxis:axis + alignedTo:alignment + withFixedSpacing:spacing + insetSpacing:shouldSpaceInsets + matchedSizes:YES]; } /** @@ -176,22 +235,29 @@ - (NSArray *)autoDistributeViewsAlongAxis:(ALAxis)axis withFixedSpacing:(CGFloat Views will have fixed spacing between them, and can optionally be constrained to the same size in the dimension along the axis. The first and last views can optionally be inset from their superview by the same amount of spacing as between views. - @param axis The axis along which to distribute the subviews. - @param spacing The fixed amount of spacing between each subview. + @param axis The axis along which to distribute the views. + @param alignment The attribute to use to align all the views to one another. + @param spacing The fixed amount of spacing between each view. @param shouldSpaceInsets Whether the first and last views should be equally inset from their superview. @param shouldMatchSizes Whether all views will be constrained to be the same size in the dimension along the axis. NOTE: All views must specify an intrinsic content size if passing NO, otherwise the layout will be ambiguous! - @param alignment The way in which the subviews will be aligned. @return An array of constraints added. */ -- (NSArray *)autoDistributeViewsAlongAxis:(ALAxis)axis withFixedSpacing:(CGFloat)spacing insetSpacing:(BOOL)shouldSpaceInsets matchedSizes:(BOOL)shouldMatchSizes alignment:(NSLayoutFormatOptions)alignment +- (NSArray *)autoDistributeViewsAlongAxis:(ALAxis)axis + alignedTo:(ALAttribute)alignment + withFixedSpacing:(CGFloat)spacing + insetSpacing:(BOOL)shouldSpaceInsets + matchedSizes:(BOOL)shouldMatchSizes { NSAssert([self al_containsMinimumNumberOfViews:2], @"This array must contain at least 2 views to distribute."); ALDimension matchedDimension; ALEdge firstEdge, lastEdge; switch (axis) { case ALAxisHorizontal: - case ALAxisBaseline: + case ALAxisBaseline: // same value as ALAxisLastBaseline +#if __PureLayout_MinBaseSDK_iOS_8_0 + case ALAxisFirstBaseline: +#endif /* __PureLayout_MinBaseSDK_iOS_8_0 */ matchedDimension = ALDimensionWidth; firstEdge = ALEdgeLeading; lastEdge = ALEdgeTrailing; @@ -220,7 +286,7 @@ - (NSArray *)autoDistributeViewsAlongAxis:(ALAxis)axis withFixedSpacing:(CGFloat if (shouldMatchSizes) { [constraints addObject:[view autoMatchDimension:matchedDimension toDimension:matchedDimension ofView:previousView]]; } - [constraints addObject:[view al_alignToView:previousView withOption:alignment forAxis:axis]]; + [constraints addObject:[view al_alignAttribute:alignment toView:previousView forAxis:axis]]; } else { // First view @@ -241,14 +307,19 @@ - (NSArray *)autoDistributeViewsAlongAxis:(ALAxis)axis withFixedSpacing:(CGFloat Views will be the same size (fixed) in the dimension along the axis and will have spacing (variable) between them, including from the first and last views to their superview. - @param axis The axis along which to distribute the subviews. - @param size The fixed size of each subview in the dimension along the given axis. - @param alignment The way in which the subviews will be aligned. + @param axis The axis along which to distribute the views. + @param alignment The attribute to use to align all the views to one another. + @param size The fixed size of each view in the dimension along the given axis. @return An array of constraints added. */ -- (NSArray *)autoDistributeViewsAlongAxis:(ALAxis)axis withFixedSize:(CGFloat)size alignment:(NSLayoutFormatOptions)alignment +- (NSArray *)autoDistributeViewsAlongAxis:(ALAxis)axis + alignedTo:(ALAttribute)alignment + withFixedSize:(CGFloat)size { - return [self autoDistributeViewsAlongAxis:axis withFixedSize:size insetSpacing:YES alignment:alignment]; + return [self autoDistributeViewsAlongAxis:axis + alignedTo:alignment + withFixedSize:size + insetSpacing:YES]; } /** @@ -256,20 +327,26 @@ - (NSArray *)autoDistributeViewsAlongAxis:(ALAxis)axis withFixedSize:(CGFloat)si Views will be the same size (fixed) in the dimension along the axis and will have spacing (variable) between them. The first and last views can optionally be inset from their superview by the same amount of spacing as between views. - @param axis The axis along which to distribute the subviews. - @param size The fixed size of each subview in the dimension along the given axis. + @param axis The axis along which to distribute the views. + @param alignment The attribute to use to align all the views to one another. + @param size The fixed size of each view in the dimension along the given axis. @param shouldSpaceInsets Whether the first and last views should be equally inset from their superview. - @param alignment The way in which the subviews will be aligned. @return An array of constraints added. */ -- (NSArray *)autoDistributeViewsAlongAxis:(ALAxis)axis withFixedSize:(CGFloat)size insetSpacing:(BOOL)shouldSpaceInsets alignment:(NSLayoutFormatOptions)alignment +- (NSArray *)autoDistributeViewsAlongAxis:(ALAxis)axis + alignedTo:(ALAttribute)alignment + withFixedSize:(CGFloat)size + insetSpacing:(BOOL)shouldSpaceInsets { NSAssert([self al_containsMinimumNumberOfViews:2], @"This array must contain at least 2 views to distribute."); ALDimension fixedDimension; NSLayoutAttribute attribute; switch (axis) { case ALAxisHorizontal: - case ALAxisBaseline: + case ALAxisBaseline: // same value as ALAxisLastBaseline +#if __PureLayout_MinBaseSDK_iOS_8_0 + case ALAxisFirstBaseline: +#endif /* __PureLayout_MinBaseSDK_iOS_8_0 */ fixedDimension = ALDimensionWidth; attribute = NSLayoutAttributeCenterX; break; @@ -295,17 +372,17 @@ - (NSArray *)autoDistributeViewsAlongAxis:(ALAxis)axis withFixedSize:(CGFloat)si [constraints addObject:[view autoSetDimension:fixedDimension toSize:size]]; CGFloat multiplier, constant; if (shouldSpaceInsets) { - multiplier = (i * 2.0f + 2.0f) / (numberOfViews + 1.0f); - constant = (multiplier - 1.0f) * size / 2.0f; + multiplier = (i * 2.0 + 2.0) / (numberOfViews + 1.0); + constant = (multiplier - 1.0) * size / 2.0; } else { - multiplier = (i * 2.0f) / (numberOfViews - 1.0f); - constant = (-multiplier + 1.0f) * size / 2.0f; + multiplier = (i * 2.0) / (numberOfViews - 1.0); + constant = (-multiplier + 1.0) * size / 2.0; } NSLayoutConstraint *constraint = [NSLayoutConstraint constraintWithItem:view attribute:attribute relatedBy:NSLayoutRelationEqual toItem:commonSuperview attribute:attribute multiplier:multiplier constant:constant]; - [commonSuperview al_addConstraintUsingGlobalPriority:constraint]; + [constraint autoInstall]; [constraints addObject:constraint]; if (previousView) { - [constraints addObject:[view al_alignToView:previousView withOption:alignment forAxis:axis]]; + [constraints addObject:[view al_alignAttribute:alignment toView:previousView forAxis:axis]]; } previousView = view; } diff --git a/TableViewCellWithAutoLayout/PureLayout/NSLayoutConstraint+PureLayout.h b/TableViewCellWithAutoLayout/PureLayout/NSLayoutConstraint+PureLayout.h index 6733c59..065d10a 100755 --- a/TableViewCellWithAutoLayout/PureLayout/NSLayoutConstraint+PureLayout.h +++ b/TableViewCellWithAutoLayout/PureLayout/NSLayoutConstraint+PureLayout.h @@ -1,6 +1,6 @@ // // NSLayoutConstraint+PureLayout.h -// v1.1.0 +// v2.0.1 // https://github.com/smileyborg/PureLayout // // Copyright (c) 2013-2014 Tyler Fox @@ -32,14 +32,27 @@ #pragma mark - NSLayoutConstraint+PureLayout /** - A category on NSLayoutConstraint that allows constraints to be easily removed. + A category on NSLayoutConstraint that allows constraints to be easily installed & removed. */ @interface NSLayoutConstraint (PureLayout) -/** Adds the constraint to the appropriate view. */ + +#pragma mark Install & Remove Constraints + +/** Activates the the constraint. */ - (void)autoInstall; -/** Removes the constraint from the view it has been added to. */ +/** Deactivates the constraint. */ - (void)autoRemove; + +#pragma mark Identify Constraints + +#if __PureLayout_MinBaseSDK_iOS_8_0 || __PureLayout_MinBaseSDK_OSX_10_10 + +/** Sets the string as the identifier for this constraint. Available in iOS 7.0 and OS X 10.9 and later. */ +- (instancetype)autoIdentify:(NSString *)identifer; + +#endif /* __PureLayout_MinBaseSDK_iOS_8_0 || __PureLayout_MinBaseSDK_OSX_10_10 */ + @end diff --git a/TableViewCellWithAutoLayout/PureLayout/NSLayoutConstraint+PureLayout.m b/TableViewCellWithAutoLayout/PureLayout/NSLayoutConstraint+PureLayout.m index cb3fc74..d0c1550 100755 --- a/TableViewCellWithAutoLayout/PureLayout/NSLayoutConstraint+PureLayout.m +++ b/TableViewCellWithAutoLayout/PureLayout/NSLayoutConstraint+PureLayout.m @@ -1,6 +1,6 @@ // // NSLayoutConstraint+PureLayout.m -// v1.1.0 +// v2.0.1 // https://github.com/smileyborg/PureLayout // // Copyright (c) 2013-2014 Tyler Fox @@ -35,33 +35,278 @@ @implementation NSLayoutConstraint (PureLayout) + +#pragma mark Installing & Removing Constraints + /** - Adds the constraint to the appropriate view. + Activates the constraint. */ - (void)autoInstall { +#if __PureLayout_MinBaseSDK_iOS_8_0 + if ([self respondsToSelector:@selector(setActive:)]) { + [ALView al_applyGlobalStateToConstraint:self]; + if (![ALView al_preventAutomaticConstraintInstallation]) { + self.active = YES; + } + return; + } +#endif /* __PureLayout_MinBaseSDK_iOS_8_0 */ + NSAssert(self.firstItem || self.secondItem, @"Can't install a constraint with nil firstItem and secondItem."); if (self.firstItem) { if (self.secondItem) { NSAssert([self.firstItem isKindOfClass:[ALView class]] && [self.secondItem isKindOfClass:[ALView class]], @"Can only automatically install a constraint if both items are views."); ALView *commonSuperview = [self.firstItem al_commonSuperviewWithView:self.secondItem]; - [commonSuperview al_addConstraintUsingGlobalPriority:self]; + [commonSuperview al_addConstraint:self]; } else { NSAssert([self.firstItem isKindOfClass:[ALView class]], @"Can only automatically install a constraint if the item is a view."); - [self.firstItem al_addConstraintUsingGlobalPriority:self]; + [self.firstItem al_addConstraint:self]; } } else { NSAssert([self.secondItem isKindOfClass:[ALView class]], @"Can only automatically install a constraint if the item is a view."); - [self.secondItem al_addConstraintUsingGlobalPriority:self]; + [self.secondItem al_addConstraint:self]; } } /** - Removes the constraint from the view it has been added to. + Deactivates the constraint. */ - (void)autoRemove { - [ALView autoRemoveConstraint:self]; +#if __PureLayout_MinBaseSDK_iOS_8_0 + if ([self respondsToSelector:@selector(setActive:)]) { + self.active = NO; + return; + } +#endif /* __PureLayout_MinBaseSDK_iOS_8_0 */ + + if (self.secondItem) { + ALView *commonSuperview = [self.firstItem al_commonSuperviewWithView:self.secondItem]; + while (commonSuperview) { + if ([commonSuperview.constraints containsObject:self]) { + [commonSuperview removeConstraint:self]; + return; + } + commonSuperview = commonSuperview.superview; + } + } + else { + [self.firstItem removeConstraint:self]; + return; + } + NSAssert(nil, @"Failed to remove constraint: %@", self); +} + + +#pragma mark Identify Constraints + +#if __PureLayout_MinBaseSDK_iOS_8_0 || __PureLayout_MinBaseSDK_OSX_10_10 + +/** + Sets the string as the identifier for this constraint. Available in iOS 7.0 and OS X 10.9 and later. + The identifer will be printed along with the constraint's description. + This is helpful to document a constraint's purpose and aid in debugging. + + @param identifier A string used to identify this constraint. + @return This constraint. + */ +- (instancetype)autoIdentify:(NSString *)identifer +{ + if ([self respondsToSelector:@selector(setIdentifier:)]) { + self.identifier = identifer; + } + return self; +} + +#endif /* __PureLayout_MinBaseSDK_iOS_8_0 || __PureLayout_MinBaseSDK_OSX_10_10 */ + + +#pragma mark Internal Methods + +/** + Returns the corresponding NSLayoutAttribute for the given ALAttribute. + + @return The layout attribute for the given ALAttribute. + */ ++ (NSLayoutAttribute)al_layoutAttributeForAttribute:(ALAttribute)attribute +{ + NSLayoutAttribute layoutAttribute = NSLayoutAttributeNotAnAttribute; + switch (attribute) { + case ALEdgeLeft: + layoutAttribute = NSLayoutAttributeLeft; + break; + case ALEdgeRight: + layoutAttribute = NSLayoutAttributeRight; + break; + case ALEdgeTop: + layoutAttribute = NSLayoutAttributeTop; + break; + case ALEdgeBottom: + layoutAttribute = NSLayoutAttributeBottom; + break; + case ALEdgeLeading: + layoutAttribute = NSLayoutAttributeLeading; + break; + case ALEdgeTrailing: + layoutAttribute = NSLayoutAttributeTrailing; + break; + case ALDimensionWidth: + layoutAttribute = NSLayoutAttributeWidth; + break; + case ALDimensionHeight: + layoutAttribute = NSLayoutAttributeHeight; + break; + case ALAxisVertical: + layoutAttribute = NSLayoutAttributeCenterX; + break; + case ALAxisHorizontal: + layoutAttribute = NSLayoutAttributeCenterY; + break; + case ALAxisBaseline: // same value as ALAxisLastBaseline + layoutAttribute = NSLayoutAttributeBaseline; + break; +#if __PureLayout_MinBaseSDK_iOS_8_0 + case ALAxisFirstBaseline: + NSAssert(__PureLayout_MinSysVer_iOS_8_0, @"ALAxisFirstBaseline is only supported on iOS 8.0 or higher."); + layoutAttribute = NSLayoutAttributeFirstBaseline; + break; + case ALMarginLeft: + NSAssert(__PureLayout_MinSysVer_iOS_8_0, @"ALEdgeLeftMargin is only supported on iOS 8.0 or higher."); + layoutAttribute = NSLayoutAttributeLeftMargin; + break; + case ALMarginRight: + NSAssert(__PureLayout_MinSysVer_iOS_8_0, @"ALEdgeRightMargin is only supported on iOS 8.0 or higher."); + layoutAttribute = NSLayoutAttributeRightMargin; + break; + case ALMarginTop: + NSAssert(__PureLayout_MinSysVer_iOS_8_0, @"ALEdgeTopMargin is only supported on iOS 8.0 or higher."); + layoutAttribute = NSLayoutAttributeTopMargin; + break; + case ALMarginBottom: + NSAssert(__PureLayout_MinSysVer_iOS_8_0, @"ALEdgeBottomMargin is only supported on iOS 8.0 or higher."); + layoutAttribute = NSLayoutAttributeBottomMargin; + break; + case ALMarginLeading: + NSAssert(__PureLayout_MinSysVer_iOS_8_0, @"ALEdgeLeadingMargin is only supported on iOS 8.0 or higher."); + layoutAttribute = NSLayoutAttributeLeadingMargin; + break; + case ALMarginTrailing: + NSAssert(__PureLayout_MinSysVer_iOS_8_0, @"ALEdgeTrailingMargin is only supported on iOS 8.0 or higher."); + layoutAttribute = NSLayoutAttributeTrailingMargin; + break; + case ALMarginAxisVertical: + NSAssert(__PureLayout_MinSysVer_iOS_8_0, @"ALAxisVerticalMargin is only supported on iOS 8.0 or higher."); + layoutAttribute = NSLayoutAttributeCenterXWithinMargins; + break; + case ALMarginAxisHorizontal: + NSAssert(__PureLayout_MinSysVer_iOS_8_0, @"ALAxisHorizontalMargin is only supported on iOS 8.0 or higher."); + layoutAttribute = NSLayoutAttributeCenterYWithinMargins; + break; +#endif /* __PureLayout_MinBaseSDK_iOS_8_0 */ + default: + NSAssert(nil, @"Not a valid ALAttribute."); + break; + } + return layoutAttribute; +} + +/** + Returns the corresponding ALLayoutConstraintAxis for the given ALAxis. + + @return The constraint axis for the given axis. + */ ++ (ALLayoutConstraintAxis)al_constraintAxisForAxis:(ALAxis)axis +{ + ALLayoutConstraintAxis constraintAxis; + switch (axis) { + case ALAxisVertical: + constraintAxis = ALLayoutConstraintAxisVertical; + break; + case ALAxisHorizontal: + case ALAxisBaseline: // same value as ALAxisLastBaseline +#if __PureLayout_MinBaseSDK_iOS_8_0 + case ALAxisFirstBaseline: +#endif /* __PureLayout_MinBaseSDK_iOS_8_0 */ + constraintAxis = ALLayoutConstraintAxisHorizontal; + break; + default: + NSAssert(nil, @"Not a valid ALAxis."); + constraintAxis = ALLayoutConstraintAxisHorizontal; // default to a random value to satisfy the compiler + break; + } + return constraintAxis; } +#if __PureLayout_MinBaseSDK_iOS_8_0 + +/** + Returns the corresponding margin for the given edge. + + @param edge The edge to convert to the corresponding margin. + @return The margin for the given edge. + */ ++ (ALMargin)al_marginForEdge:(ALEdge)edge +{ + NSAssert(__PureLayout_MinSysVer_iOS_8_0, @"Margin attributes are only supported on iOS 8.0 or higher."); + ALMargin margin; + switch (edge) { + case ALEdgeLeft: + margin = ALMarginLeft; + break; + case ALEdgeRight: + margin = ALMarginRight; + break; + case ALEdgeTop: + margin = ALMarginTop; + break; + case ALEdgeBottom: + margin = ALMarginBottom; + break; + case ALEdgeLeading: + margin = ALMarginLeading; + break; + case ALEdgeTrailing: + margin = ALMarginTrailing; + break; + default: + NSAssert(nil, @"Not a valid ALEdge."); + margin = ALMarginLeft; // default to a random value to satisfy the compiler + break; + } + return margin; +} + +/** + Returns the corresponding margin axis for the given axis. + + @param axis The axis to convert to the corresponding margin axis. + @return The margin axis for the given axis. + */ ++ (ALMarginAxis)al_marginAxisForAxis:(ALAxis)axis +{ + NSAssert(__PureLayout_MinSysVer_iOS_8_0, @"Margin attributes are only supported on iOS 8.0 or higher."); + ALMarginAxis marginAxis; + switch (axis) { + case ALAxisVertical: + marginAxis = ALMarginAxisVertical; + break; + case ALAxisHorizontal: + marginAxis = ALMarginAxisHorizontal; + break; + case ALAxisBaseline: + case ALAxisFirstBaseline: + NSAssert(nil, @"The baseline axis attributes do not have corresponding margin axis attributes."); + marginAxis = ALMarginAxisVertical; // default to a random value to satisfy the compiler + break; + default: + NSAssert(nil, @"Not a valid ALAxis."); + marginAxis = ALMarginAxisVertical; // default to a random value to satisfy the compiler + break; + } + return marginAxis; +} + +#endif /* __PureLayout_MinBaseSDK_iOS_8_0 */ + @end diff --git a/TableViewCellWithAutoLayout/PureLayout/PureLayout+Internal.h b/TableViewCellWithAutoLayout/PureLayout/PureLayout+Internal.h index 4e0e006..65e0e7a 100644 --- a/TableViewCellWithAutoLayout/PureLayout/PureLayout+Internal.h +++ b/TableViewCellWithAutoLayout/PureLayout/PureLayout+Internal.h @@ -1,6 +1,6 @@ // // PureLayout+Internal.h -// v1.1.0 +// v2.0.1 // https://github.com/smileyborg/PureLayout // // Copyright (c) 2014 Tyler Fox @@ -34,15 +34,14 @@ */ @interface ALView (PureLayoutInternal) -+ (NSLayoutAttribute)al_attributeForEdge:(ALEdge)edge; -+ (NSLayoutAttribute)al_attributeForAxis:(ALAxis)axis; -+ (NSLayoutAttribute)al_attributeForDimension:(ALDimension)dimension; -+ (NSLayoutAttribute)al_attributeForALAttribute:(NSInteger)ALAttribute; -+ (ALLayoutConstraintAxis)al_constraintAxisForAxis:(ALAxis)axis; - -- (void)al_addConstraintUsingGlobalPriority:(NSLayoutConstraint *)constraint; -- (ALView *)al_commonSuperviewWithView:(ALView *)peerView; -- (NSLayoutConstraint *)al_alignToView:(ALView *)peerView withOption:(NSLayoutFormatOptions)alignment forAxis:(ALAxis)axis; ++ (BOOL)al_preventAutomaticConstraintInstallation; ++ (BOOL)al_isExecutingPriorityConstraintsBlock; ++ (ALLayoutPriority)al_currentGlobalConstraintPriority; ++ (NSString *)al_currentGlobalConstraintIdentifier; ++ (void)al_applyGlobalStateToConstraint:(NSLayoutConstraint *)constraint; +- (void)al_addConstraint:(NSLayoutConstraint *)constraint; +- (ALView *)al_commonSuperviewWithView:(ALView *)otherView; +- (NSLayoutConstraint *)al_alignAttribute:(ALAttribute)attribute toView:(ALView *)otherView forAxis:(ALAxis)axis; @end @@ -57,3 +56,18 @@ - (NSArray *)al_copyViewsOnly; @end + + +/** + A category that exposes the internal (private) helper methods of the NSLayoutConstraint+PureLayout category. + */ +@interface NSLayoutConstraint (PureLayoutInternal) + ++ (NSLayoutAttribute)al_layoutAttributeForAttribute:(ALAttribute)attribute; ++ (ALLayoutConstraintAxis)al_constraintAxisForAxis:(ALAxis)axis; +#if __PureLayout_MinBaseSDK_iOS_8_0 ++ (ALMargin)al_marginForEdge:(ALEdge)edge; ++ (ALMarginAxis)al_marginAxisForAxis:(ALAxis)axis; +#endif /* __PureLayout_MinBaseSDK_iOS_8_0 */ + +@end diff --git a/TableViewCellWithAutoLayout/PureLayout/PureLayout.h b/TableViewCellWithAutoLayout/PureLayout/PureLayout.h index cd223b2..62f5039 100755 --- a/TableViewCellWithAutoLayout/PureLayout/PureLayout.h +++ b/TableViewCellWithAutoLayout/PureLayout/PureLayout.h @@ -1,6 +1,6 @@ // // PureLayout.h -// v1.1.0 +// v2.0.1 // https://github.com/smileyborg/PureLayout // // Copyright (c) 2014 Tyler Fox diff --git a/TableViewCellWithAutoLayout/PureLayout/PureLayoutDefines.h b/TableViewCellWithAutoLayout/PureLayout/PureLayoutDefines.h index 86d4f1b..1c34026 100755 --- a/TableViewCellWithAutoLayout/PureLayout/PureLayoutDefines.h +++ b/TableViewCellWithAutoLayout/PureLayout/PureLayoutDefines.h @@ -1,6 +1,6 @@ // // PureLayoutDefines.h -// v1.1.0 +// v2.0.1 // https://github.com/smileyborg/PureLayout // // Copyright (c) 2014 Tyler Fox @@ -31,6 +31,13 @@ #import +#define __PureLayout_MinBaseSDK_iOS_8_0 TARGET_OS_IPHONE && __IPHONE_OS_VERSION_MAX_ALLOWED > __IPHONE_7_1 +#define __PureLayout_MinSysVer_iOS_7_0 TARGET_OS_IPHONE && floor(NSFoundationVersionNumber) > NSFoundationVersionNumber_iOS_6_1 +#define __PureLayout_MinSysVer_iOS_8_0 TARGET_OS_IPHONE && floor(NSFoundationVersionNumber) > NSFoundationVersionNumber_iOS_7_1 + +#define __PureLayout_MinBaseSDK_OSX_10_10 !TARGET_OS_IPHONE && __MAC_OS_X_VERSION_MAX_ALLOWED > __MAC_10_9 +#define __PureLayout_MinSysVer_OSX_10_9 !TARGET_OS_IPHONE && floor(NSFoundationVersionNumber) > NSFoundationVersionNumber10_8_4 + #if TARGET_OS_IPHONE #import @@ -76,7 +83,7 @@ #endif /* TARGET_OS_IPHONE */ -#pragma mark ALAttributes +#pragma mark PureLayout Attributes /** Constants that represent edges of a view. */ typedef NS_ENUM(NSInteger, ALEdge) { @@ -104,12 +111,96 @@ typedef NS_ENUM(NSInteger, ALDimension) { /** Constants that represent axes of a view. */ typedef NS_ENUM(NSInteger, ALAxis) { - /** A vertical line through the center of the view. */ + /** A vertical line through the middle of the view's left and right edges. */ ALAxisVertical = NSLayoutAttributeCenterX, - /** A horizontal line through the center of the view. */ + /** A horizontal line through the middle of the view's top and bottom edges. */ ALAxisHorizontal = NSLayoutAttributeCenterY, - /** A horizontal line at the text baseline (not applicable to all views). */ - ALAxisBaseline = NSLayoutAttributeBaseline + + /** A horizontal line at the baseline of the last line of text in the view. (For views that do not draw text, will be equivalent to ALEdgeBottom.) Same as ALAxisLastBaseline. */ + ALAxisBaseline = NSLayoutAttributeBaseline, + /** A horizontal line at the baseline of the last line of text in the view. (For views that do not draw text, will be equivalent to ALEdgeBottom.) */ + ALAxisLastBaseline = ALAxisBaseline, + #if __PureLayout_MinBaseSDK_iOS_8_0 + /** A horizontal line at the baseline of the first line of text in a view. (For views that do not draw text, will be equivalent to ALEdgeTop.) Available in iOS 8.0 and later. */ + ALAxisFirstBaseline = NSLayoutAttributeFirstBaseline + #endif /* __PureLayout_MinBaseSDK_iOS_8_0 */ +}; + +#if __PureLayout_MinBaseSDK_iOS_8_0 + +/** Constants that represent layout margins of a view. Available in iOS 8.0 and later. */ +typedef NS_ENUM(NSInteger, ALMargin) { + /** The left margin of the view, based on the view's layoutMargins left inset. */ + ALMarginLeft = NSLayoutAttributeLeftMargin, + /** The right margin of the view, based on the view's layoutMargins right inset. */ + ALMarginRight = NSLayoutAttributeRightMargin, + /** The top margin of the view, based on the view's layoutMargins top inset. */ + ALMarginTop = NSLayoutAttributeTopMargin, + /** The bottom margin of the view, based on the view's layoutMargins bottom inset. */ + ALMarginBottom = NSLayoutAttributeBottomMargin, + /** The leading margin of the view, based on the view's layoutMargins left/right (depending on language direction) inset. */ + ALMarginLeading = NSLayoutAttributeLeadingMargin, + /** The trailing margin of the view, based on the view's layoutMargins left/right (depending on language direction) inset. */ + ALMarginTrailing = NSLayoutAttributeTrailingMargin +}; + +/** Constants that represent axes of the layout margins of a view. Available in iOS 8.0 and later. */ +typedef NS_ENUM(NSInteger, ALMarginAxis) { + /** A vertical line through the middle of the view's left and right margins. */ + ALMarginAxisVertical = NSLayoutAttributeCenterXWithinMargins, + /** A horizontal line through the middle of the view's top and bottom margins. */ + ALMarginAxisHorizontal = NSLayoutAttributeCenterYWithinMargins +}; + +#endif /* __PureLayout_MinBaseSDK_iOS_8_0 */ + +/** An attribute of a view that can be used in auto layout constraints. These constants are identical to the more specific enum types: + ALEdge, ALAxis, ALDimension, ALMargin, ALMarginAxis. It is safe to cast a more specific enum type to the ALAttribute type. */ +typedef NS_ENUM(NSInteger, ALAttribute) { + /** The left edge of the view. */ + ALAttributeLeft = ALEdgeLeft, + /** The right edge of the view. */ + ALAttributeRight = ALEdgeRight, + /** The top edge of the view. */ + ALAttributeTop = ALEdgeTop, + /** The bottom edge of the view. */ + ALAttributeBottom = ALEdgeBottom, + /** The leading edge of the view (left edge for left-to-right languages like English, right edge for right-to-left languages like Arabic). */ + ALAttributeLeading = ALEdgeLeading, + /** The trailing edge of the view (right edge for left-to-right languages like English, left edge for right-to-left languages like Arabic). */ + ALAttributeTrailing = ALEdgeTrailing, + /** The width of the view. */ + ALAttributeWidth = ALDimensionWidth, + /** The height of the view. */ + ALAttributeHeight = ALDimensionHeight, + /** A vertical line through the middle of the view's left and right edges. */ + ALAttributeVertical = ALAxisVertical, + /** A horizontal line through the middle of the view's top and bottom edges. */ + ALAttributeHorizontal = ALAxisHorizontal, + /** A horizontal line at the baseline of the last line of text in the view. (For views that do not draw text, will be equivalent to ALEdgeBottom.) Same as ALAxisLastBaseline. */ + ALAttributeBaseline = ALAxisBaseline, + /** A horizontal line at the baseline of the last line of text in the view. (For views that do not draw text, will be equivalent to ALEdgeBottom.) */ + ALAttributeLastBaseline = ALAxisLastBaseline, +#if __PureLayout_MinBaseSDK_iOS_8_0 + /** A horizontal line at the baseline of the first line of text in a view. (For views that do not draw text, will be equivalent to ALEdgeTop.) Available in iOS 8.0 and later. */ + ALAttributeFirstBaseline = ALAxisFirstBaseline, + /** The left margin of the view, based on the view's layoutMargins left inset. */ + ALAttributeMarginLeft = ALMarginLeft, + /** The right margin of the view, based on the view's layoutMargins right inset. */ + ALAttributeMarginRight = ALMarginRight, + /** The top margin of the view, based on the view's layoutMargins top inset. */ + ALAttributeMarginTop = ALMarginTop, + /** The bottom margin of the view, based on the view's layoutMargins bottom inset. */ + ALAttributeMarginBottom = ALMarginBottom, + /** The leading margin of the view, based on the view's layoutMargins left/right (depending on language direction) inset. */ + ALAttributeMarginLeading = ALMarginLeading, + /** The trailing margin of the view, based on the view's layoutMargins left/right (depending on language direction) inset. */ + ALAttributeMarginTrailing = ALMarginTrailing, + /** A vertical line through the middle of the view's left and right margins. */ + ALAttributeMarginAxisVertical = ALMarginAxisVertical, + /** A horizontal line through the middle of the view's top and bottom margins. */ + ALAttributeMarginAxisHorizontal = ALMarginAxisHorizontal +#endif /* __PureLayout_MinBaseSDK_iOS_8_0 */ }; /** A block containing method calls to the PureLayout API. Takes no arguments and has no return value. */ From dcae5882f336877701e9b0bab404335e461fff75 Mon Sep 17 00:00:00 2001 From: Tyler Fox Date: Wed, 12 Nov 2014 16:00:59 -0800 Subject: [PATCH 20/30] Fix Xcode 6.1 compile issues --- TableViewCellWithAutoLayout/AppDelegate.swift | 2 +- .../TableViewController/TableViewCell.swift | 2 +- .../TableViewController/TableViewController.swift | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/TableViewCellWithAutoLayout/AppDelegate.swift b/TableViewCellWithAutoLayout/AppDelegate.swift index 785ef73..b031fb5 100644 --- a/TableViewCellWithAutoLayout/AppDelegate.swift +++ b/TableViewCellWithAutoLayout/AppDelegate.swift @@ -17,7 +17,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate // Override point for customization after application launch. window = UIWindow(frame: UIScreen.mainScreen().bounds) var viewController = TableViewController(style: .Plain) - window!.rootViewController = UINavigationController(rootViewController: viewController!) + window!.rootViewController = UINavigationController(rootViewController: viewController) window!.makeKeyAndVisible() return true } diff --git a/TableViewCellWithAutoLayout/TableViewController/TableViewCell.swift b/TableViewCellWithAutoLayout/TableViewController/TableViewCell.swift index fae56ca..27ca665 100644 --- a/TableViewCellWithAutoLayout/TableViewController/TableViewCell.swift +++ b/TableViewCellWithAutoLayout/TableViewController/TableViewCell.swift @@ -19,7 +19,7 @@ class TableViewCell: UITableViewCell var titleLabel: UILabel = UILabel.newAutoLayoutView() var bodyLabel: UILabel = UILabel.newAutoLayoutView() - override init?(style: UITableViewCellStyle, reuseIdentifier: String!) + override init(style: UITableViewCellStyle, reuseIdentifier: String!) { super.init(style: style, reuseIdentifier: reuseIdentifier) diff --git a/TableViewCellWithAutoLayout/TableViewController/TableViewController.swift b/TableViewCellWithAutoLayout/TableViewController/TableViewController.swift index f793680..c9024fc 100644 --- a/TableViewCellWithAutoLayout/TableViewController/TableViewController.swift +++ b/TableViewCellWithAutoLayout/TableViewController/TableViewController.swift @@ -18,7 +18,7 @@ class TableViewController: UITableViewController super.init(nibName: nibNameOrNil, bundle: nibBundleOrNil) } - override init?(style: UITableViewStyle) + override init(style: UITableViewStyle) { super.init(style: style) From 945a2819e267da5f771bfd4186511c25fe5bb5aa Mon Sep 17 00:00:00 2001 From: dautermann Date: Fri, 6 Mar 2015 13:27:52 -0500 Subject: [PATCH 21/30] Make project compatible with Swift 1.2 --- TableViewCellWithAutoLayout/AppDelegate.swift | 2 +- .../TableViewController/TableViewController.swift | 7 +------ 2 files changed, 2 insertions(+), 7 deletions(-) diff --git a/TableViewCellWithAutoLayout/AppDelegate.swift b/TableViewCellWithAutoLayout/AppDelegate.swift index b031fb5..ae6fac3 100644 --- a/TableViewCellWithAutoLayout/AppDelegate.swift +++ b/TableViewCellWithAutoLayout/AppDelegate.swift @@ -12,7 +12,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate { var window: UIWindow? - func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: NSDictionary?) -> Bool + func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject : AnyObject]?) -> Bool { // Override point for customization after application launch. window = UIWindow(frame: UIScreen.mainScreen().bounds) diff --git a/TableViewCellWithAutoLayout/TableViewController/TableViewController.swift b/TableViewCellWithAutoLayout/TableViewController/TableViewController.swift index c9024fc..a84d985 100644 --- a/TableViewCellWithAutoLayout/TableViewController/TableViewController.swift +++ b/TableViewCellWithAutoLayout/TableViewController/TableViewController.swift @@ -13,11 +13,6 @@ class TableViewController: UITableViewController var model = Model() - override init(nibName nibNameOrNil: String!, bundle nibBundleOrNil: NSBundle!) - { - super.init(nibName: nibNameOrNil, bundle: nibBundleOrNil) - } - override init(style: UITableViewStyle) { super.init(style: style) @@ -94,7 +89,7 @@ class TableViewController: UITableViewController model = Model() - tableView.deleteRowsAtIndexPaths(rowsToDelete, withRowAnimation: .Automatic) + tableView.deleteRowsAtIndexPaths(rowsToDelete as [AnyObject], withRowAnimation: .Automatic) } // Adds a single row to the table view From e9cb8152113fc9017617e0f3c059e4281aca2d85 Mon Sep 17 00:00:00 2001 From: Tyler Fox Date: Tue, 10 Mar 2015 08:01:03 -0700 Subject: [PATCH 22/30] Update PureLayout to v2.0.5 --- .../PureLayout/ALView+PureLayout.h | 10 +-- .../PureLayout/ALView+PureLayout.m | 89 ++++++++++++++----- .../PureLayout/NSArray+PureLayout.h | 9 +- .../PureLayout/NSArray+PureLayout.m | 79 +++++++++++++--- .../NSLayoutConstraint+PureLayout.h | 6 +- .../NSLayoutConstraint+PureLayout.m | 22 ++--- .../PureLayout/PureLayout+Internal.h | 9 +- .../PureLayout/PureLayout.h | 6 +- .../PureLayout/PureLayoutDefines.h | 80 ++++++++--------- 9 files changed, 204 insertions(+), 106 deletions(-) diff --git a/TableViewCellWithAutoLayout/PureLayout/ALView+PureLayout.h b/TableViewCellWithAutoLayout/PureLayout/ALView+PureLayout.h index fb0b502..ae74922 100755 --- a/TableViewCellWithAutoLayout/PureLayout/ALView+PureLayout.h +++ b/TableViewCellWithAutoLayout/PureLayout/ALView+PureLayout.h @@ -1,10 +1,10 @@ // // ALView+PureLayout.h -// v2.0.1 +// v2.0.5 // https://github.com/smileyborg/PureLayout // // Copyright (c) 2012 Richard Turton -// Copyright (c) 2013-2014 Tyler Fox +// Copyright (c) 2013-2015 Tyler Fox // // This code is distributed under the terms and conditions of the MIT license. // @@ -50,8 +50,8 @@ #pragma mark Create Constraints Without Installing /** Prevents constraints created in the given constraints block from being automatically installed (activated). - The created constraints returned from each PureLayout API call must be stored, as they are not retained. */ -+ (void)autoCreateConstraintsWithoutInstalling:(ALConstraintsBlock)block; + The constraints created from calls to the PureLayout API in the block are returned in a single array. */ ++ (NSArray *)autoCreateConstraintsWithoutInstalling:(ALConstraintsBlock)block; #pragma mark Set Priority For Constraints @@ -67,7 +67,7 @@ /** Sets the identifier for all constraints created using the PureLayout API within the given constraints block. NOTE: This method will have no effect (and will NOT set the identifier) on constraints created or added without using the PureLayout API! */ -+ (void)autoSetIdentifier:(NSString *)identifer forConstraints:(ALConstraintsBlock)block; ++ (void)autoSetIdentifier:(NSString *)identifier forConstraints:(ALConstraintsBlock)block; #endif /* __PureLayout_MinBaseSDK_iOS_8_0 */ diff --git a/TableViewCellWithAutoLayout/PureLayout/ALView+PureLayout.m b/TableViewCellWithAutoLayout/PureLayout/ALView+PureLayout.m index 30c0e45..81817ca 100755 --- a/TableViewCellWithAutoLayout/PureLayout/ALView+PureLayout.m +++ b/TableViewCellWithAutoLayout/PureLayout/ALView+PureLayout.m @@ -1,10 +1,10 @@ // // ALView+PureLayout.m -// v2.0.1 +// v2.0.5 // https://github.com/smileyborg/PureLayout // // Copyright (c) 2012 Richard Turton -// Copyright (c) 2013-2014 Tyler Fox +// Copyright (c) 2013-2015 Tyler Fox // // This code is distributed under the terms and conditions of the MIT license. // @@ -66,36 +66,61 @@ - (instancetype)initForAutoLayout #pragma mark Create Constraints Without Installing /** - A global variable that is incremented when the constraints block passed in to the - +[autoCreateConstraintsWithoutInstalling:] method begins executing, and decremented when the block - finishes executing. As a result, this variable will be 0 when not inside a constraints block, and - greater than 0 when inside a constraints block. + A global variable that stores a stack of arrays of constraints created without being immediately installed. + When executing a constraints block passed into the +[autoCreateConstraintsWithoutInstalling:] method, a new + mutable array is pushed onto this stack, and all constraints created with PureLayout in the block are added + to this array. When the block finishes executing, the array is popped off this stack. Automatic constraint + installation is prevented if this stack contains at least 1 array. + NOTE: Access to this variable is not synchronized (and should only be done on the main thread). */ -static NSUInteger _al_preventAutomaticConstraintInstallationCount = 0; +static NSMutableArray *_al_arraysOfCreatedConstraints = nil; + +/** + Accessor for the global state that stores arrays of constraints created without being installed. + */ ++ (NSMutableArray *)al_arraysOfCreatedConstraints +{ + if (!_al_arraysOfCreatedConstraints) { + _al_arraysOfCreatedConstraints = [NSMutableArray new]; + } + return _al_arraysOfCreatedConstraints; +} + +/** + Accessor for the current mutable array of constraints created without being immediately installed. + */ ++ (NSMutableArray *)al_currentArrayOfCreatedConstraints +{ + return [[self al_arraysOfCreatedConstraints] lastObject]; +} /** Accessor for the global state that determines whether automatic constraint installation should be prevented. */ + (BOOL)al_preventAutomaticConstraintInstallation { - return _al_preventAutomaticConstraintInstallationCount > 0; + return [[self al_arraysOfCreatedConstraints] count] > 0; } /** Prevents constraints created in the given constraints block from being automatically installed (activated). - The created constraints returned from each PureLayout API call must be stored, as they are not retained. + The constraints created from calls to the PureLayout API in the block are returned in a single array. @param block A block of method calls to the PureLayout API that create constraints. + @return An array of the constraints that were created from calls to the PureLayout API inside the block. */ -+ (void)autoCreateConstraintsWithoutInstalling:(ALConstraintsBlock)block ++ (NSArray *)autoCreateConstraintsWithoutInstalling:(ALConstraintsBlock)block { NSAssert(block, @"The constraints block cannot be nil."); + NSArray *createdConstraints = nil; if (block) { - _al_preventAutomaticConstraintInstallationCount++; + [[self al_arraysOfCreatedConstraints] addObject:[NSMutableArray new]]; block(); - _al_preventAutomaticConstraintInstallationCount--; + createdConstraints = [self al_currentArrayOfCreatedConstraints]; + [[self al_arraysOfCreatedConstraints] removeLastObject]; } + return createdConstraints; } @@ -141,7 +166,7 @@ + (ALLayoutPriority)al_currentGlobalConstraintPriority */ + (BOOL)al_isExecutingPriorityConstraintsBlock { - return [[ALView al_globalConstraintPriorities] count] > 0; + return [[self al_globalConstraintPriorities] count] > 0; } /** @@ -158,9 +183,9 @@ + (void)autoSetPriority:(ALLayoutPriority)priority forConstraints:(ALConstraints { NSAssert(block, @"The constraints block cannot be nil."); if (block) { - [[ALView al_globalConstraintPriorities] addObject:@(priority)]; + [[self al_globalConstraintPriorities] addObject:@(priority)]; block(); - [[ALView al_globalConstraintPriorities] removeLastObject]; + [[self al_globalConstraintPriorities] removeLastObject]; } } @@ -210,20 +235,20 @@ + (NSString *)al_currentGlobalConstraintIdentifier NOTE: This method will have no effect (and will NOT set the identifier) on constraints created or added without using the PureLayout API! - @param identifer A string used to identify all constraints created in the constraints block. + @param identifier A string used to identify all constraints created in the constraints block. @param block A block of method calls to the PureLayout API that create and install constraints. */ -+ (void)autoSetIdentifier:(NSString *)identifer forConstraints:(ALConstraintsBlock)block ++ (void)autoSetIdentifier:(NSString *)identifier forConstraints:(ALConstraintsBlock)block { NSAssert(block, @"The constraints block cannot be nil."); - NSAssert(identifer, @"The identifier string cannot be nil."); + NSAssert(identifier, @"The identifier string cannot be nil."); if (block) { - if (identifer) { - [[ALView al_globalConstraintIdentifiers] addObject:identifer]; + if (identifier) { + [[self al_globalConstraintIdentifiers] addObject:identifier]; } block(); - if (identifer) { - [[ALView al_globalConstraintIdentifiers] removeLastObject]; + if (identifier) { + [[self al_globalConstraintIdentifiers] removeLastObject]; } } } @@ -965,7 +990,9 @@ + (void)al_applyGlobalStateToConstraint:(NSLayoutConstraint *)constraint - (void)al_addConstraint:(NSLayoutConstraint *)constraint { [ALView al_applyGlobalStateToConstraint:constraint]; - if (![ALView al_preventAutomaticConstraintInstallation]) { + if ([ALView al_preventAutomaticConstraintInstallation]) { + [[ALView al_currentArrayOfCreatedConstraints] addObject:constraint]; + } else { [self addConstraint:constraint]; } } @@ -1051,8 +1078,22 @@ - (NSLayoutConstraint *)al_alignAttribute:(ALAttribute)attribute toView:(ALView NSAssert(axis == ALAxisVertical, @"Cannot align views that are distributed horizontally with ALAttributeTrailing."); constraint = [self autoPinEdge:ALEdgeTrailing toEdge:ALEdgeTrailing ofView:otherView]; break; + + // All of the below attributes are invalid as alignment options. Listing them explicitly (even though they just fall through to the default case) to avoid an incomplete switch statement warning from the compiler. + case ALAttributeWidth: + case ALAttributeHeight: +#if __PureLayout_MinBaseSDK_iOS_8_0 + case ALAttributeMarginLeft: + case ALAttributeMarginRight: + case ALAttributeMarginTop: + case ALAttributeMarginBottom: + case ALAttributeMarginLeading: + case ALAttributeMarginTrailing: + case ALAttributeMarginAxisVertical: + case ALAttributeMarginAxisHorizontal: +#endif /* __PureLayout_MinBaseSDK_iOS_8_0 */ default: - NSAssert(nil, @"Unsupported alignment option."); + NSAssert(nil, @"Unsupported attribute for alignment."); break; } return constraint; diff --git a/TableViewCellWithAutoLayout/PureLayout/NSArray+PureLayout.h b/TableViewCellWithAutoLayout/PureLayout/NSArray+PureLayout.h index 74d4c22..10ece57 100755 --- a/TableViewCellWithAutoLayout/PureLayout/NSArray+PureLayout.h +++ b/TableViewCellWithAutoLayout/PureLayout/NSArray+PureLayout.h @@ -1,10 +1,10 @@ // // NSArray+PureLayout.h -// v2.0.1 +// v2.0.5 // https://github.com/smileyborg/PureLayout // // Copyright (c) 2012 Richard Turton -// Copyright (c) 2013-2014 Tyler Fox +// Copyright (c) 2013-2015 Tyler Fox // // This code is distributed under the terms and conditions of the MIT license. // @@ -51,7 +51,7 @@ #if __PureLayout_MinBaseSDK_iOS_8_0 /** Sets the string as the identifier for the constraints in this array. Available in iOS 7.0 and OS X 10.9 and later. */ -- (instancetype)autoIdentifyConstraints:(NSString *)identifer; +- (instancetype)autoIdentifyConstraints:(NSString *)identifier; #endif /* __PureLayout_MinBaseSDK_iOS_8_0 */ @@ -70,6 +70,9 @@ /** Sets the given dimension of all the views in this array to a given size. */ - (NSArray *)autoSetViewsDimension:(ALDimension)dimension toSize:(CGFloat)size; +/** Sets all of the views in this array to a given size. */ +- (NSArray *)autoSetViewsDimensionsToSize:(CGSize)size; + /** Distributes the views in this array equally along the selected axis in their superview. Views will be the same size (variable) in the dimension along the axis and will have spacing (fixed) between them. */ - (NSArray *)autoDistributeViewsAlongAxis:(ALAxis)axis diff --git a/TableViewCellWithAutoLayout/PureLayout/NSArray+PureLayout.m b/TableViewCellWithAutoLayout/PureLayout/NSArray+PureLayout.m index d2178d6..81c0fb5 100755 --- a/TableViewCellWithAutoLayout/PureLayout/NSArray+PureLayout.m +++ b/TableViewCellWithAutoLayout/PureLayout/NSArray+PureLayout.m @@ -1,10 +1,10 @@ // // NSArray+PureLayout.m -// v2.0.1 +// v2.0.5 // https://github.com/smileyborg/PureLayout // // Copyright (c) 2012 Richard Turton -// Copyright (c) 2013-2014 Tyler Fox +// Copyright (c) 2013-2015 Tyler Fox // // This code is distributed under the terms and conditions of the MIT license. // @@ -45,6 +45,22 @@ @implementation NSArray (PureLayout) */ - (void)autoInstallConstraints { +#if __PureLayout_MinBaseSDK_iOS_8_0 || __PureLayout_MinBaseSDK_OSX_10_10 + if ([NSLayoutConstraint respondsToSelector:@selector(activateConstraints:)]) { + for (id object in self) { + if ([object isKindOfClass:[NSLayoutConstraint class]]) { + [ALView al_applyGlobalStateToConstraint:object]; + } + } + if ([ALView al_preventAutomaticConstraintInstallation]) { + [[ALView al_currentArrayOfCreatedConstraints] addObjectsFromArray:self]; + } else { + [NSLayoutConstraint activateConstraints:self]; + } + return; + } +#endif /* __PureLayout_MinBaseSDK_iOS_8_0 || __PureLayout_MinBaseSDK_OSX_10_10 */ + for (id object in self) { if ([object isKindOfClass:[NSLayoutConstraint class]]) { [((NSLayoutConstraint *)object) autoInstall]; @@ -57,6 +73,13 @@ - (void)autoInstallConstraints */ - (void)autoRemoveConstraints { +#if __PureLayout_MinBaseSDK_iOS_8_0 || __PureLayout_MinBaseSDK_OSX_10_10 + if ([NSLayoutConstraint respondsToSelector:@selector(deactivateConstraints:)]) { + [NSLayoutConstraint deactivateConstraints:self]; + return; + } +#endif /* __PureLayout_MinBaseSDK_iOS_8_0 || __PureLayout_MinBaseSDK_OSX_10_10 */ + for (id object in self) { if ([object isKindOfClass:[NSLayoutConstraint class]]) { [((NSLayoutConstraint *)object) autoRemove]; @@ -68,17 +91,17 @@ - (void)autoRemoveConstraints /** Sets the string as the identifier for the constraints in this array. Available in iOS 7.0 and OS X 10.9 and later. - The identifer will be printed along with each constraint's description. + The identifier will be printed along with each constraint's description. This is helpful to document the constraints' purpose and aid in debugging. @param identifier A string used to identify the constraints in this array. @return This array. */ -- (instancetype)autoIdentifyConstraints:(NSString *)identifer +- (instancetype)autoIdentifyConstraints:(NSString *)identifier { for (id object in self) { if ([object isKindOfClass:[NSLayoutConstraint class]]) { - [((NSLayoutConstraint *)object) autoIdentify:identifer]; + [((NSLayoutConstraint *)object) autoIdentify:identifier]; } } return self; @@ -93,7 +116,7 @@ - (instancetype)autoIdentifyConstraints:(NSString *)identifer Aligns views in this array to one another along a given edge. Note: This array must contain at least 2 views, and all views must share a common superview. - @param edge The edge to which the subviews will be aligned. + @param edge The edge to which the views will be aligned. @return An array of constraints added. */ - (NSArray *)autoAlignViewsToEdge:(ALEdge)edge @@ -118,7 +141,7 @@ - (NSArray *)autoAlignViewsToEdge:(ALEdge)edge Aligns views in this array to one another along a given axis. Note: This array must contain at least 2 views, and all views must share a common superview. - @param axis The axis to which to subviews will be aligned. + @param axis The axis to which the views will be aligned. @return An array of constraints added. */ - (NSArray *)autoAlignViewsToAxis:(ALAxis)axis @@ -143,7 +166,7 @@ - (NSArray *)autoAlignViewsToAxis:(ALAxis)axis Matches a given dimension of all the views in this array. Note: This array must contain at least 2 views, and all views must share a common superview. - @param dimension The dimension to match for all of the subviews. + @param dimension The dimension to match for all of the views. @return An array of constraints added. */ - (NSArray *)autoMatchViewsDimension:(ALDimension)dimension @@ -168,8 +191,8 @@ - (NSArray *)autoMatchViewsDimension:(ALDimension)dimension Sets the given dimension of all the views in this array to a given size. Note: This array must contain at least 1 view. - @param dimension The dimension of each of the subviews to set. - @param size The size to set the given dimension of each subview to. + @param dimension The dimension of each of the views to set. + @param size The size to set the given dimension of each view to. @return An array of constraints added. */ - (NSArray *)autoSetViewsDimension:(ALDimension)dimension toSize:(CGFloat)size @@ -186,6 +209,21 @@ - (NSArray *)autoSetViewsDimension:(ALDimension)dimension toSize:(CGFloat)size return constraints; } +/** + Sets all of the views in this array to a given size. + Note: This array must contain at least 1 view. + + @param size The size to set each view's dimensions to. + @return An array of constraints added. + */ +- (NSArray *)autoSetViewsDimensionsToSize:(CGSize)size +{ + NSMutableArray *constraints = [NSMutableArray new]; + [constraints addObjectsFromArray:[self autoSetViewsDimension:ALDimensionWidth toSize:size.width]]; + [constraints addObjectsFromArray:[self autoSetViewsDimension:ALDimensionHeight toSize:size.height]]; + return constraints; +} + /** Distributes the views in this array equally along the selected axis in their superview. @@ -194,7 +232,7 @@ Views will be the same size (variable) in the dimension along the axis and will @param axis The axis along which to distribute the views. @param alignment The attribute to use to align all the views to one another. - @param spacing The fixed amount of spacing between each subview, before the first subview and after the last subview. + @param spacing The fixed amount of spacing between each view. @return An array of constraints added. */ - (NSArray *)autoDistributeViewsAlongAxis:(ALAxis)axis @@ -214,7 +252,7 @@ Views will be the same size (variable) in the dimension along the axis and will @param axis The axis along which to distribute the views. @param alignment The attribute to use to align all the views to one another. - @param spacing The fixed amount of spacing between each subview. + @param spacing The fixed amount of spacing between each view. @param shouldSpaceInsets Whether the first and last views should be equally inset from their superview. @return An array of constraints added. */ @@ -358,8 +396,17 @@ - (NSArray *)autoDistributeViewsAlongAxis:(ALAxis)axis NSAssert(nil, @"Not a valid ALAxis."); return nil; } - BOOL isRightToLeftLanguage = [NSLocale characterDirectionForLanguage:[[NSBundle mainBundle] preferredLocalizations][0]] == NSLocaleLanguageDirectionRightToLeft; - BOOL shouldFlipOrder = isRightToLeftLanguage && (axis != ALAxisVertical); // imitate the effect of leading/trailing when distributing horizontally +#if TARGET_OS_IPHONE +# if !defined(PURELAYOUT_APP_EXTENSIONS) + BOOL isRightToLeftLayout = [[UIApplication sharedApplication] userInterfaceLayoutDirection] == UIUserInterfaceLayoutDirectionRightToLeft; +# else + // App Extensions may not access -[UIApplication sharedApplication]; fall back to checking the bundle's preferred localization character direction + BOOL isRightToLeftLayout = [NSLocale characterDirectionForLanguage:[[NSBundle mainBundle] preferredLocalizations][0]] == NSLocaleLanguageDirectionRightToLeft; +# endif /* !defined(PURELAYOUT_APP_EXTENSIONS) */ +#else + BOOL isRightToLeftLayout = [[NSApplication sharedApplication] userInterfaceLayoutDirection] == NSUserInterfaceLayoutDirectionRightToLeft; +#endif /* TARGET_OS_IPHONE */ + BOOL shouldFlipOrder = isRightToLeftLayout && (axis != ALAxisVertical); // imitate the effect of leading/trailing when distributing horizontally NSMutableArray *constraints = [NSMutableArray new]; NSArray *views = [self al_copyViewsOnly]; @@ -378,6 +425,10 @@ - (NSArray *)autoDistributeViewsAlongAxis:(ALAxis)axis multiplier = (i * 2.0) / (numberOfViews - 1.0); constant = (-multiplier + 1.0) * size / 2.0; } + // If the multiplier is very close to 0, set it to the minimum value to prevent the second item in the constraint from being lost. Filed as rdar://19168380 + if (fabs(multiplier) < kMULTIPLIER_MIN_VALUE) { + multiplier = kMULTIPLIER_MIN_VALUE; + } NSLayoutConstraint *constraint = [NSLayoutConstraint constraintWithItem:view attribute:attribute relatedBy:NSLayoutRelationEqual toItem:commonSuperview attribute:attribute multiplier:multiplier constant:constant]; [constraint autoInstall]; [constraints addObject:constraint]; diff --git a/TableViewCellWithAutoLayout/PureLayout/NSLayoutConstraint+PureLayout.h b/TableViewCellWithAutoLayout/PureLayout/NSLayoutConstraint+PureLayout.h index 065d10a..87797f6 100755 --- a/TableViewCellWithAutoLayout/PureLayout/NSLayoutConstraint+PureLayout.h +++ b/TableViewCellWithAutoLayout/PureLayout/NSLayoutConstraint+PureLayout.h @@ -1,9 +1,9 @@ // // NSLayoutConstraint+PureLayout.h -// v2.0.1 +// v2.0.5 // https://github.com/smileyborg/PureLayout // -// Copyright (c) 2013-2014 Tyler Fox +// Copyright (c) 2013-2015 Tyler Fox // // This code is distributed under the terms and conditions of the MIT license. // @@ -51,7 +51,7 @@ #if __PureLayout_MinBaseSDK_iOS_8_0 || __PureLayout_MinBaseSDK_OSX_10_10 /** Sets the string as the identifier for this constraint. Available in iOS 7.0 and OS X 10.9 and later. */ -- (instancetype)autoIdentify:(NSString *)identifer; +- (instancetype)autoIdentify:(NSString *)identifier; #endif /* __PureLayout_MinBaseSDK_iOS_8_0 || __PureLayout_MinBaseSDK_OSX_10_10 */ diff --git a/TableViewCellWithAutoLayout/PureLayout/NSLayoutConstraint+PureLayout.m b/TableViewCellWithAutoLayout/PureLayout/NSLayoutConstraint+PureLayout.m index d0c1550..1a290b5 100755 --- a/TableViewCellWithAutoLayout/PureLayout/NSLayoutConstraint+PureLayout.m +++ b/TableViewCellWithAutoLayout/PureLayout/NSLayoutConstraint+PureLayout.m @@ -1,9 +1,9 @@ // // NSLayoutConstraint+PureLayout.m -// v2.0.1 +// v2.0.5 // https://github.com/smileyborg/PureLayout // -// Copyright (c) 2013-2014 Tyler Fox +// Copyright (c) 2013-2015 Tyler Fox // // This code is distributed under the terms and conditions of the MIT license. // @@ -43,15 +43,17 @@ @implementation NSLayoutConstraint (PureLayout) */ - (void)autoInstall { -#if __PureLayout_MinBaseSDK_iOS_8_0 +#if __PureLayout_MinBaseSDK_iOS_8_0 || __PureLayout_MinBaseSDK_OSX_10_10 if ([self respondsToSelector:@selector(setActive:)]) { [ALView al_applyGlobalStateToConstraint:self]; - if (![ALView al_preventAutomaticConstraintInstallation]) { + if ([ALView al_preventAutomaticConstraintInstallation]) { + [[ALView al_currentArrayOfCreatedConstraints] addObject:self]; + } else { self.active = YES; } return; } -#endif /* __PureLayout_MinBaseSDK_iOS_8_0 */ +#endif /* __PureLayout_MinBaseSDK_iOS_8_0 || __PureLayout_MinBaseSDK_OSX_10_10 */ NSAssert(self.firstItem || self.secondItem, @"Can't install a constraint with nil firstItem and secondItem."); if (self.firstItem) { @@ -74,12 +76,12 @@ - (void)autoInstall */ - (void)autoRemove { -#if __PureLayout_MinBaseSDK_iOS_8_0 +#if __PureLayout_MinBaseSDK_iOS_8_0 || __PureLayout_MinBaseSDK_OSX_10_10 if ([self respondsToSelector:@selector(setActive:)]) { self.active = NO; return; } -#endif /* __PureLayout_MinBaseSDK_iOS_8_0 */ +#endif /* __PureLayout_MinBaseSDK_iOS_8_0 || __PureLayout_MinBaseSDK_OSX_10_10 */ if (self.secondItem) { ALView *commonSuperview = [self.firstItem al_commonSuperviewWithView:self.secondItem]; @@ -105,16 +107,16 @@ - (void)autoRemove /** Sets the string as the identifier for this constraint. Available in iOS 7.0 and OS X 10.9 and later. - The identifer will be printed along with the constraint's description. + The identifier will be printed along with the constraint's description. This is helpful to document a constraint's purpose and aid in debugging. @param identifier A string used to identify this constraint. @return This constraint. */ -- (instancetype)autoIdentify:(NSString *)identifer +- (instancetype)autoIdentify:(NSString *)identifier { if ([self respondsToSelector:@selector(setIdentifier:)]) { - self.identifier = identifer; + self.identifier = identifier; } return self; } diff --git a/TableViewCellWithAutoLayout/PureLayout/PureLayout+Internal.h b/TableViewCellWithAutoLayout/PureLayout/PureLayout+Internal.h index 65e0e7a..28fbfcf 100644 --- a/TableViewCellWithAutoLayout/PureLayout/PureLayout+Internal.h +++ b/TableViewCellWithAutoLayout/PureLayout/PureLayout+Internal.h @@ -1,9 +1,9 @@ // // PureLayout+Internal.h -// v2.0.1 +// v2.0.5 // https://github.com/smileyborg/PureLayout // -// Copyright (c) 2014 Tyler Fox +// Copyright (c) 2014-2015 Tyler Fox // // This code is distributed under the terms and conditions of the MIT license. // @@ -28,6 +28,10 @@ #import "PureLayoutDefines.h" +/** A constant that represents the smallest valid positive value for the multiplier of a constraint, + since a value of 0 will cause the second item to be lost in the internal auto layout engine. */ +static const CGFloat kMULTIPLIER_MIN_VALUE = 0.00001; // very small floating point numbers (e.g. CGFLOAT_MIN) can cause problems + /** A category that exposes the internal (private) helper methods of the ALView+PureLayout category. @@ -35,6 +39,7 @@ @interface ALView (PureLayoutInternal) + (BOOL)al_preventAutomaticConstraintInstallation; ++ (NSMutableArray *)al_currentArrayOfCreatedConstraints; + (BOOL)al_isExecutingPriorityConstraintsBlock; + (ALLayoutPriority)al_currentGlobalConstraintPriority; + (NSString *)al_currentGlobalConstraintIdentifier; diff --git a/TableViewCellWithAutoLayout/PureLayout/PureLayout.h b/TableViewCellWithAutoLayout/PureLayout/PureLayout.h index 62f5039..8c47775 100755 --- a/TableViewCellWithAutoLayout/PureLayout/PureLayout.h +++ b/TableViewCellWithAutoLayout/PureLayout/PureLayout.h @@ -1,9 +1,9 @@ // // PureLayout.h -// v2.0.1 +// v2.0.5 // https://github.com/smileyborg/PureLayout // -// Copyright (c) 2014 Tyler Fox +// Copyright (c) 2014-2015 Tyler Fox // // This code is distributed under the terms and conditions of the MIT license. // @@ -33,4 +33,4 @@ #import "NSArray+PureLayout.h" #import "NSLayoutConstraint+PureLayout.h" -#endif /* PureLayout_h */ \ No newline at end of file +#endif /* PureLayout_h */ diff --git a/TableViewCellWithAutoLayout/PureLayout/PureLayoutDefines.h b/TableViewCellWithAutoLayout/PureLayout/PureLayoutDefines.h index 1c34026..2f10152 100755 --- a/TableViewCellWithAutoLayout/PureLayout/PureLayoutDefines.h +++ b/TableViewCellWithAutoLayout/PureLayout/PureLayoutDefines.h @@ -1,9 +1,9 @@ // // PureLayoutDefines.h -// v2.0.1 +// v2.0.5 // https://github.com/smileyborg/PureLayout // -// Copyright (c) 2014 Tyler Fox +// Copyright (c) 2014-2015 Tyler Fox // // This code is distributed under the terms and conditions of the MIT license. // @@ -39,47 +39,43 @@ #define __PureLayout_MinSysVer_OSX_10_9 !TARGET_OS_IPHONE && floor(NSFoundationVersionNumber) > NSFoundationVersionNumber10_8_4 #if TARGET_OS_IPHONE - - #import - - #define ALView UIView - #define ALEdgeInsets UIEdgeInsets - #define ALEdgeInsetsZero UIEdgeInsetsZero - #define ALEdgeInsetsMake UIEdgeInsetsMake - #define ALLayoutConstraintAxis UILayoutConstraintAxis - #define ALLayoutConstraintOrientation ALLayoutConstraintAxis - #define ALLayoutConstraintAxisHorizontal UILayoutConstraintAxisHorizontal - #define ALLayoutConstraintAxisVertical UILayoutConstraintAxisVertical - #define ALLayoutConstraintOrientationHorizontal ALLayoutConstraintAxisHorizontal - #define ALLayoutConstraintOrientationVertical ALLayoutConstraintAxisVertical - #define ALLayoutPriority UILayoutPriority - #define ALLayoutPriorityRequired UILayoutPriorityRequired - #define ALLayoutPriorityDefaultHigh UILayoutPriorityDefaultHigh - #define ALLayoutPriorityDefaultLow UILayoutPriorityDefaultLow - #define ALLayoutPriorityFittingSizeLevel UILayoutPriorityFittingSizeLevel - #define ALLayoutPriorityFittingSizeCompression ALLayoutPriorityFittingSizeLevel - +# import + +# define ALView UIView +# define ALEdgeInsets UIEdgeInsets +# define ALEdgeInsetsZero UIEdgeInsetsZero +# define ALEdgeInsetsMake UIEdgeInsetsMake +# define ALLayoutConstraintAxis UILayoutConstraintAxis +# define ALLayoutConstraintOrientation ALLayoutConstraintAxis +# define ALLayoutConstraintAxisHorizontal UILayoutConstraintAxisHorizontal +# define ALLayoutConstraintAxisVertical UILayoutConstraintAxisVertical +# define ALLayoutConstraintOrientationHorizontal ALLayoutConstraintAxisHorizontal +# define ALLayoutConstraintOrientationVertical ALLayoutConstraintAxisVertical +# define ALLayoutPriority UILayoutPriority +# define ALLayoutPriorityRequired UILayoutPriorityRequired +# define ALLayoutPriorityDefaultHigh UILayoutPriorityDefaultHigh +# define ALLayoutPriorityDefaultLow UILayoutPriorityDefaultLow +# define ALLayoutPriorityFittingSizeLevel UILayoutPriorityFittingSizeLevel +# define ALLayoutPriorityFittingSizeCompression ALLayoutPriorityFittingSizeLevel #else - - #import - - #define ALView NSView - #define ALEdgeInsets NSEdgeInsets - #define ALEdgeInsetsZero NSEdgeInsetsMake(0, 0, 0, 0) - #define ALEdgeInsetsMake NSEdgeInsetsMake - #define ALLayoutConstraintOrientation NSLayoutConstraintOrientation - #define ALLayoutConstraintAxis ALLayoutConstraintOrientation - #define ALLayoutConstraintOrientationHorizontal NSLayoutConstraintOrientationHorizontal - #define ALLayoutConstraintOrientationVertical NSLayoutConstraintOrientationVertical - #define ALLayoutConstraintAxisHorizontal ALLayoutConstraintOrientationHorizontal - #define ALLayoutConstraintAxisVertical ALLayoutConstraintOrientationVertical - #define ALLayoutPriority NSLayoutPriority - #define ALLayoutPriorityRequired NSLayoutPriorityRequired - #define ALLayoutPriorityDefaultHigh NSLayoutPriorityDefaultHigh - #define ALLayoutPriorityDefaultLow NSLayoutPriorityDefaultLow - #define ALLayoutPriorityFittingSizeCompression NSLayoutPriorityFittingSizeCompression - #define ALLayoutPriorityFittingSizeLevel ALLayoutPriorityFittingSizeCompression - +# import + +# define ALView NSView +# define ALEdgeInsets NSEdgeInsets +# define ALEdgeInsetsZero NSEdgeInsetsMake(0, 0, 0, 0) +# define ALEdgeInsetsMake NSEdgeInsetsMake +# define ALLayoutConstraintOrientation NSLayoutConstraintOrientation +# define ALLayoutConstraintAxis ALLayoutConstraintOrientation +# define ALLayoutConstraintOrientationHorizontal NSLayoutConstraintOrientationHorizontal +# define ALLayoutConstraintOrientationVertical NSLayoutConstraintOrientationVertical +# define ALLayoutConstraintAxisHorizontal ALLayoutConstraintOrientationHorizontal +# define ALLayoutConstraintAxisVertical ALLayoutConstraintOrientationVertical +# define ALLayoutPriority NSLayoutPriority +# define ALLayoutPriorityRequired NSLayoutPriorityRequired +# define ALLayoutPriorityDefaultHigh NSLayoutPriorityDefaultHigh +# define ALLayoutPriorityDefaultLow NSLayoutPriorityDefaultLow +# define ALLayoutPriorityFittingSizeCompression NSLayoutPriorityFittingSizeCompression +# define ALLayoutPriorityFittingSizeLevel ALLayoutPriorityFittingSizeCompression #endif /* TARGET_OS_IPHONE */ From abe00ef1bd52fb1b62c467678e2c0ba4f3f2f348 Mon Sep 17 00:00:00 2001 From: Tyler Fox Date: Sat, 28 Mar 2015 16:59:13 -0700 Subject: [PATCH 23/30] Minor refactoring for compatibility with Swift 1.1 and 1.2 Fixes #21 - Avoid overriding any of the table view controller initializers - Refactor and modernize the Model class --- .../TableViewController/Model.swift | 22 +++++++++---------- .../TableViewController.swift | 18 ++------------- 2 files changed, 13 insertions(+), 27 deletions(-) diff --git a/TableViewCellWithAutoLayout/TableViewController/Model.swift b/TableViewCellWithAutoLayout/TableViewController/Model.swift index 7d844c7..8a1af43 100644 --- a/TableViewCellWithAutoLayout/TableViewController/Model.swift +++ b/TableViewCellWithAutoLayout/TableViewController/Model.swift @@ -9,27 +9,27 @@ import Foundation class Model { - var dataArray: Array<(title:String, body:String)> = Array() - - func populate() + var dataArray: [(title: String, body: String)] = Array() + + init(populated: Bool) { - var fontFamilies = UIFont.familyNames() - - for familyName: AnyObject in fontFamilies { - if let familyNameString: String = familyName as? String { - dataArray.append((title: familyNameString, body: randomLoremIpsum())) + if (populated) { + for familyName: AnyObject in UIFont.familyNames() { + if let familyNameString = familyName as? String { + dataArray.append((title: familyNameString, body: randomLoremIpsum())) + } } } } func addSingleItem() { - var fontFamilies = UIFont.familyNames() + let fontFamilies = UIFont.familyNames() let r = random() % fontFamilies.count let familyName: AnyObject = fontFamilies[r] - if let familyNameString: String = familyName as? String { + if let familyNameString = familyName as? String { dataArray.append((title: familyNameString, body: randomLoremIpsum())) } } @@ -38,7 +38,7 @@ class Model { let loremIpsum = "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Praesent non quam ac massa viverra semper. Maecenas mattis justo ac augue volutpat congue. Maecenas laoreet, nulla eu faucibus gravida, felis orci dictum risus, sed sodales sem eros eget risus. Morbi imperdiet sed diam et sodales. Vestibulum ut est id mauris ultrices gravida. Nulla malesuada metus ut erat malesuada, vitae ornare neque semper. Aenean a commodo justo, vel placerat odio. Curabitur vitae consequat tortor. Aenean eu magna ante. Integer tristique elit ac augue laoreet, eget pulvinar lacus dictum. Cras eleifend lacus eget pharetra elementum. Etiam fermentum eu felis eu tristique. Integer eu purus vitae turpis blandit consectetur. Nulla facilisi. Praesent bibendum massa eu metus pulvinar, quis tristique nunc commodo. Ut varius aliquam elit, a tincidunt elit aliquam non. Nunc ac leo purus. Proin condimentum placerat ligula, at tristique neque scelerisque ut. Suspendisse ut congue enim. Integer id sem nisl. Nam dignissim, lectus et dictum sollicitudin, libero augue ullamcorper justo, nec consectetur dolor arcu sed justo. Proin rutrum pharetra lectus, vel gravida ante venenatis sed. Mauris lacinia urna vehicula felis aliquet venenatis. Suspendisse non pretium sapien. Proin id dolor ultricies, dictum augue non, euismod ante. Vivamus et luctus augue, a luctus mi. Maecenas sit amet felis in magna vestibulum viverra vel ut est. Suspendisse potenti. Morbi nec odio pretium lacus laoreet volutpat sit amet at ipsum. Etiam pretium purus vitae tortor auctor, quis cursus metus vehicula. Integer ultricies facilisis arcu, non congue orci pharetra quis. Vivamus pulvinar ligula neque, et vehicula ipsum euismod quis." - var loremIpsumArray = loremIpsum.componentsSeparatedByString(" ") + let loremIpsumArray = loremIpsum.componentsSeparatedByString(" ") let minimumNumberOfWords = 3 let r = max(minimumNumberOfWords, random() % loremIpsumArray.count) // get a random number r, where: minimumNumberOfWords <= r <= loremIpsumArray.count diff --git a/TableViewCellWithAutoLayout/TableViewController/TableViewController.swift b/TableViewCellWithAutoLayout/TableViewController/TableViewController.swift index a84d985..9a29a80 100644 --- a/TableViewCellWithAutoLayout/TableViewController/TableViewController.swift +++ b/TableViewCellWithAutoLayout/TableViewController/TableViewController.swift @@ -11,21 +11,7 @@ class TableViewController: UITableViewController { let kCellIdentifier = "CellIdentifier" - var model = Model() - - override init(style: UITableViewStyle) - { - super.init(style: style) - - model.populate() - } - - required init(coder aDecoder: NSCoder) - { - super.init(coder: aDecoder) - - model.populate() - } + var model = Model(populated: true) override func viewDidLoad() { @@ -87,7 +73,7 @@ class TableViewController: UITableViewController rowsToDelete.addObject(NSIndexPath(forRow: i, inSection: 0)) } - model = Model() + model = Model(populated: false) tableView.deleteRowsAtIndexPaths(rowsToDelete as [AnyObject], withRowAnimation: .Automatic) } From 54b22c7e26449e105ecf78bff4bc724e6a4d527c Mon Sep 17 00:00:00 2001 From: Tyler Fox Date: Thu, 18 Jun 2015 08:40:04 -0700 Subject: [PATCH 24/30] Update with Xcode 7 All these changes are backwards-compatible with earlier Swift versions. --- TableViewCellWithAutoLayout.xcodeproj/project.pbxproj | 10 ++++++++-- TableViewCellWithAutoLayout/AppDelegate.swift | 2 +- .../TableViewCellWithAutoLayout-Info.plist | 2 +- .../TableViewController/Model.swift | 2 +- .../TableViewController/TableViewController.swift | 6 +++--- .../TableViewCellWithAutoLayoutTests-Info.plist | 2 +- 6 files changed, 15 insertions(+), 9 deletions(-) diff --git a/TableViewCellWithAutoLayout.xcodeproj/project.pbxproj b/TableViewCellWithAutoLayout.xcodeproj/project.pbxproj index fee95aa..4873dcd 100644 --- a/TableViewCellWithAutoLayout.xcodeproj/project.pbxproj +++ b/TableViewCellWithAutoLayout.xcodeproj/project.pbxproj @@ -254,8 +254,9 @@ isa = PBXProject; attributes = { CLASSPREFIX = RJ; - LastUpgradeCheck = 0600; - ORGANIZATIONNAME = RobotJackalope; + LastSwiftUpdateCheck = 0700; + LastUpgradeCheck = 0700; + ORGANIZATIONNAME = smileyborg; TargetAttributes = { 99BCDCBB18008C0000B8E66B = { TestTargetID = 99BCDCA018008C0000B8E66B; @@ -373,6 +374,7 @@ CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; COPY_PHASE_STRIP = NO; + ENABLE_TESTABILITY = YES; GCC_C_LANGUAGE_STANDARD = gnu99; GCC_DYNAMIC_NO_PIC = NO; GCC_OPTIMIZATION_LEVEL = 0; @@ -438,6 +440,7 @@ INFOPLIST_FILE = "TableViewCellWithAutoLayout/TableViewCellWithAutoLayout-Info.plist"; IPHONEOS_DEPLOYMENT_TARGET = 8.0; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; + PRODUCT_BUNDLE_IDENTIFIER = "com.smileyborg.${PRODUCT_NAME:rfc1034identifier}"; PRODUCT_NAME = "$(TARGET_NAME)"; SWIFT_OBJC_BRIDGING_HEADER = "TableViewCellWithAutoLayout/TableViewController/TableViewCellWithAutoLayout-Bridging-Header.h"; SWIFT_OPTIMIZATION_LEVEL = "-Onone"; @@ -456,6 +459,7 @@ INFOPLIST_FILE = "TableViewCellWithAutoLayout/TableViewCellWithAutoLayout-Info.plist"; IPHONEOS_DEPLOYMENT_TARGET = 8.0; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; + PRODUCT_BUNDLE_IDENTIFIER = "com.smileyborg.${PRODUCT_NAME:rfc1034identifier}"; PRODUCT_NAME = "$(TARGET_NAME)"; SWIFT_OBJC_BRIDGING_HEADER = "TableViewCellWithAutoLayout/TableViewController/TableViewCellWithAutoLayout-Bridging-Header.h"; WRAPPER_EXTENSION = app; @@ -478,6 +482,7 @@ "$(inherited)", ); INFOPLIST_FILE = "TableViewCellWithAutoLayoutTests/TableViewCellWithAutoLayoutTests-Info.plist"; + PRODUCT_BUNDLE_IDENTIFIER = "com.smileyborg.${PRODUCT_NAME:rfc1034identifier}"; PRODUCT_NAME = "$(TARGET_NAME)"; TEST_HOST = "$(BUNDLE_LOADER)"; WRAPPER_EXTENSION = xctest; @@ -496,6 +501,7 @@ GCC_PRECOMPILE_PREFIX_HEADER = YES; GCC_PREFIX_HEADER = "TableViewCellWithAutoLayout/TableViewCellWithAutoLayout-Prefix.pch"; INFOPLIST_FILE = "TableViewCellWithAutoLayoutTests/TableViewCellWithAutoLayoutTests-Info.plist"; + PRODUCT_BUNDLE_IDENTIFIER = "com.smileyborg.${PRODUCT_NAME:rfc1034identifier}"; PRODUCT_NAME = "$(TARGET_NAME)"; TEST_HOST = "$(BUNDLE_LOADER)"; WRAPPER_EXTENSION = xctest; diff --git a/TableViewCellWithAutoLayout/AppDelegate.swift b/TableViewCellWithAutoLayout/AppDelegate.swift index ae6fac3..6b0a6d7 100644 --- a/TableViewCellWithAutoLayout/AppDelegate.swift +++ b/TableViewCellWithAutoLayout/AppDelegate.swift @@ -16,7 +16,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate { // Override point for customization after application launch. window = UIWindow(frame: UIScreen.mainScreen().bounds) - var viewController = TableViewController(style: .Plain) + let viewController = TableViewController(style: .Plain) window!.rootViewController = UINavigationController(rootViewController: viewController) window!.makeKeyAndVisible() return true diff --git a/TableViewCellWithAutoLayout/TableViewCellWithAutoLayout-Info.plist b/TableViewCellWithAutoLayout/TableViewCellWithAutoLayout-Info.plist index e3bddf9..6a012bd 100644 --- a/TableViewCellWithAutoLayout/TableViewCellWithAutoLayout-Info.plist +++ b/TableViewCellWithAutoLayout/TableViewCellWithAutoLayout-Info.plist @@ -9,7 +9,7 @@ CFBundleExecutable ${EXECUTABLE_NAME} CFBundleIdentifier - com.robotjackalope.${PRODUCT_NAME:rfc1034identifier} + $(PRODUCT_BUNDLE_IDENTIFIER) CFBundleInfoDictionaryVersion 6.0 CFBundleName diff --git a/TableViewCellWithAutoLayout/TableViewController/Model.swift b/TableViewCellWithAutoLayout/TableViewController/Model.swift index 8a1af43..9acaf97 100644 --- a/TableViewCellWithAutoLayout/TableViewController/Model.swift +++ b/TableViewCellWithAutoLayout/TableViewController/Model.swift @@ -9,7 +9,7 @@ import Foundation class Model { - var dataArray: [(title: String, body: String)] = Array() + var dataArray: [(title: String, body: String)] = [] init(populated: Bool) { diff --git a/TableViewCellWithAutoLayout/TableViewController/TableViewController.swift b/TableViewCellWithAutoLayout/TableViewController/TableViewController.swift index 9a29a80..72d074d 100644 --- a/TableViewCellWithAutoLayout/TableViewController/TableViewController.swift +++ b/TableViewCellWithAutoLayout/TableViewController/TableViewController.swift @@ -68,14 +68,14 @@ class TableViewController: UITableViewController // Deletes all rows in the table view and replaces the model with a new empty one func clear() { - let rowsToDelete: NSMutableArray = [] + var rowsToDelete: [NSIndexPath] = [] for (var i = 0; i < model.dataArray.count; i++) { - rowsToDelete.addObject(NSIndexPath(forRow: i, inSection: 0)) + rowsToDelete.append(NSIndexPath(forRow: i, inSection: 0)) } model = Model(populated: false) - tableView.deleteRowsAtIndexPaths(rowsToDelete as [AnyObject], withRowAnimation: .Automatic) + tableView.deleteRowsAtIndexPaths(rowsToDelete, withRowAnimation: .Automatic) } // Adds a single row to the table view diff --git a/TableViewCellWithAutoLayoutTests/TableViewCellWithAutoLayoutTests-Info.plist b/TableViewCellWithAutoLayoutTests/TableViewCellWithAutoLayoutTests-Info.plist index 2d0aa3f..169b6f7 100644 --- a/TableViewCellWithAutoLayoutTests/TableViewCellWithAutoLayoutTests-Info.plist +++ b/TableViewCellWithAutoLayoutTests/TableViewCellWithAutoLayoutTests-Info.plist @@ -7,7 +7,7 @@ CFBundleExecutable ${EXECUTABLE_NAME} CFBundleIdentifier - com.robotjackalope.${PRODUCT_NAME:rfc1034identifier} + $(PRODUCT_BUNDLE_IDENTIFIER) CFBundleInfoDictionaryVersion 6.0 CFBundlePackageType From c1694c6e799da154f027982bb51af028681890fb Mon Sep 17 00:00:00 2001 From: Tyler Fox Date: Thu, 18 Jun 2015 08:41:36 -0700 Subject: [PATCH 25/30] Remove semicolons ;) --- .../TableViewController/TableViewController.swift | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/TableViewCellWithAutoLayout/TableViewController/TableViewController.swift b/TableViewCellWithAutoLayout/TableViewController/TableViewController.swift index 72d074d..9a3c47a 100644 --- a/TableViewCellWithAutoLayout/TableViewController/TableViewController.swift +++ b/TableViewCellWithAutoLayout/TableViewController/TableViewController.swift @@ -129,8 +129,8 @@ class TableViewController: UITableViewController return cell } - assert(false, "The dequeued table view cell was of an unknown type!"); - return UITableViewCell(); + assert(false, "The dequeued table view cell was of an unknown type!") + return UITableViewCell() } /* From daaef5e3185d6c43b865a20144d540804cd5492b Mon Sep 17 00:00:00 2001 From: Tyler Fox Date: Sun, 2 Aug 2015 15:10:44 -0700 Subject: [PATCH 26/30] Updates for Swift 2.0 in Xcode 7.0 beta 4 --- .../TableViewController/TableViewCell.swift | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/TableViewCellWithAutoLayout/TableViewController/TableViewCell.swift b/TableViewCellWithAutoLayout/TableViewController/TableViewCell.swift index 27ca665..3cf35ef 100644 --- a/TableViewCellWithAutoLayout/TableViewController/TableViewCell.swift +++ b/TableViewCellWithAutoLayout/TableViewController/TableViewCell.swift @@ -26,7 +26,7 @@ class TableViewCell: UITableViewCell setupViews() } - required init(coder aDecoder: NSCoder) + required init?(coder aDecoder: NSCoder) { super.init(coder: aDecoder) @@ -64,9 +64,7 @@ class TableViewCell: UITableViewCell // contentView.bounds = CGRect(x: 0.0, y: 0.0, width: 99999.0, height: 99999.0) // Prevent the two UILabels from being compressed below their intrinsic content height - // FIXME 7-Jun-14 Xcode 6b1: Apple Bug Report rdar://17220525: The UILayoutPriority enum is not compatible with Swift yet! - // As a temporary workaround, we're using the raw value of UILayoutPriorityRequired = 1000 - UIView.autoSetPriority(1000) { + UIView.autoSetPriority(UILayoutPriorityRequired) { self.titleLabel.autoSetContentCompressionResistancePriorityForAxis(.Vertical) self.bodyLabel.autoSetContentCompressionResistancePriorityForAxis(.Vertical) } From 4112e64d41a1a7ab3663837421863fbfa6f43c57 Mon Sep 17 00:00:00 2001 From: Tyler Fox Date: Sun, 16 Aug 2015 23:05:50 -0700 Subject: [PATCH 27/30] Update PureLayout to v3.0.0 - Remove manual integration of PureLayout source - Set up CocoaPods for this project (Pods are checked in to avoid requiring `pod install` when cloning the project) - Upgrade to PureLayout v3.0.0 - Changes required for v3.0.0 of PureLayout --- Podfile | 3 + Podfile.lock | 10 + .../Private/PureLayout/ALView+PureLayout.h | 1 + .../Private/PureLayout/NSArray+PureLayout.h | 1 + .../NSLayoutConstraint+PureLayout.h | 1 + .../Private/PureLayout/PureLayout+Internal.h | 1 + Pods/Headers/Private/PureLayout/PureLayout.h | 1 + .../Private/PureLayout/PureLayoutDefines.h | 1 + Pods/Manifest.lock | 10 + Pods/Pods.xcodeproj/project.pbxproj | 532 +++++++++++++++++ Pods/PureLayout/LICENSE | 9 + .../PureLayout/ALView+PureLayout.h | 84 +-- .../PureLayout/ALView+PureLayout.m | 358 ++---------- .../PureLayout/NSArray+PureLayout.h | 115 ++++ .../PureLayout/NSArray+PureLayout.m | 87 ++- .../NSLayoutConstraint+PureLayout.h | 40 +- .../NSLayoutConstraint+PureLayout.m | 552 ++++++++++++++++++ .../PureLayout/PureLayout+Internal.h | 27 +- .../PureLayout}/PureLayout/PureLayout.h | 9 +- .../PureLayout/PureLayoutDefines.h | 51 +- Pods/PureLayout/README.md | 219 +++++++ Pods/Target Support Files/Pods/Info.plist | 26 + .../Pods/Pods-acknowledgements.markdown | 16 + .../Pods/Pods-acknowledgements.plist | 46 ++ Pods/Target Support Files/Pods/Pods-dummy.m | 5 + .../Pods/Pods-frameworks.sh | 59 ++ .../Pods/Pods-resources.sh | 95 +++ .../Target Support Files/Pods/Pods-umbrella.h | 6 + .../Pods/Pods.debug.xcconfig | 6 + Pods/Target Support Files/Pods/Pods.modulemap | 6 + .../Pods/Pods.release.xcconfig | 6 + .../PureLayout/Info.plist | 26 + .../PureLayout/PureLayout-Private.xcconfig | 5 + .../PureLayout/PureLayout-dummy.m | 5 + .../PureLayout/PureLayout-prefix.pch | 4 + .../PureLayout/PureLayout-umbrella.h | 12 + .../PureLayout/PureLayout.modulemap | 6 + .../PureLayout/PureLayout.xcconfig | 0 README.md | 6 +- .../project.pbxproj | 101 +++- .../PureLayout/NSArray+PureLayout.h | 107 ---- .../NSLayoutConstraint+PureLayout.m | 314 ---------- .../TableViewController/Model.swift | 2 +- .../TableViewController/TableViewCell.swift | 3 +- ...leViewCellWithAutoLayout-Bridging-Header.h | 2 - 45 files changed, 2072 insertions(+), 904 deletions(-) create mode 100644 Podfile create mode 100644 Podfile.lock create mode 120000 Pods/Headers/Private/PureLayout/ALView+PureLayout.h create mode 120000 Pods/Headers/Private/PureLayout/NSArray+PureLayout.h create mode 120000 Pods/Headers/Private/PureLayout/NSLayoutConstraint+PureLayout.h create mode 120000 Pods/Headers/Private/PureLayout/PureLayout+Internal.h create mode 120000 Pods/Headers/Private/PureLayout/PureLayout.h create mode 120000 Pods/Headers/Private/PureLayout/PureLayoutDefines.h create mode 100644 Pods/Manifest.lock create mode 100644 Pods/Pods.xcodeproj/project.pbxproj create mode 100755 Pods/PureLayout/LICENSE rename {TableViewCellWithAutoLayout => Pods/PureLayout/PureLayout}/PureLayout/ALView+PureLayout.h (68%) rename {TableViewCellWithAutoLayout => Pods/PureLayout/PureLayout}/PureLayout/ALView+PureLayout.m (70%) create mode 100755 Pods/PureLayout/PureLayout/PureLayout/NSArray+PureLayout.h rename {TableViewCellWithAutoLayout => Pods/PureLayout/PureLayout}/PureLayout/NSArray+PureLayout.m (83%) rename {TableViewCellWithAutoLayout => Pods/PureLayout/PureLayout}/PureLayout/NSLayoutConstraint+PureLayout.h (55%) create mode 100755 Pods/PureLayout/PureLayout/PureLayout/NSLayoutConstraint+PureLayout.m rename {TableViewCellWithAutoLayout => Pods/PureLayout/PureLayout}/PureLayout/PureLayout+Internal.h (80%) rename {TableViewCellWithAutoLayout => Pods/PureLayout/PureLayout}/PureLayout/PureLayout.h (85%) rename {TableViewCellWithAutoLayout => Pods/PureLayout/PureLayout}/PureLayout/PureLayoutDefines.h (80%) create mode 100644 Pods/PureLayout/README.md create mode 100644 Pods/Target Support Files/Pods/Info.plist create mode 100644 Pods/Target Support Files/Pods/Pods-acknowledgements.markdown create mode 100644 Pods/Target Support Files/Pods/Pods-acknowledgements.plist create mode 100644 Pods/Target Support Files/Pods/Pods-dummy.m create mode 100755 Pods/Target Support Files/Pods/Pods-frameworks.sh create mode 100755 Pods/Target Support Files/Pods/Pods-resources.sh create mode 100644 Pods/Target Support Files/Pods/Pods-umbrella.h create mode 100644 Pods/Target Support Files/Pods/Pods.debug.xcconfig create mode 100644 Pods/Target Support Files/Pods/Pods.modulemap create mode 100644 Pods/Target Support Files/Pods/Pods.release.xcconfig create mode 100644 Pods/Target Support Files/PureLayout/Info.plist create mode 100644 Pods/Target Support Files/PureLayout/PureLayout-Private.xcconfig create mode 100644 Pods/Target Support Files/PureLayout/PureLayout-dummy.m create mode 100644 Pods/Target Support Files/PureLayout/PureLayout-prefix.pch create mode 100644 Pods/Target Support Files/PureLayout/PureLayout-umbrella.h create mode 100644 Pods/Target Support Files/PureLayout/PureLayout.modulemap create mode 100644 Pods/Target Support Files/PureLayout/PureLayout.xcconfig delete mode 100755 TableViewCellWithAutoLayout/PureLayout/NSArray+PureLayout.h delete mode 100755 TableViewCellWithAutoLayout/PureLayout/NSLayoutConstraint+PureLayout.m diff --git a/Podfile b/Podfile new file mode 100644 index 0000000..1bf41f0 --- /dev/null +++ b/Podfile @@ -0,0 +1,3 @@ +use_frameworks! + +pod 'PureLayout' diff --git a/Podfile.lock b/Podfile.lock new file mode 100644 index 0000000..c5a36c7 --- /dev/null +++ b/Podfile.lock @@ -0,0 +1,10 @@ +PODS: + - PureLayout (3.0.0) + +DEPENDENCIES: + - PureLayout + +SPEC CHECKSUMS: + PureLayout: 270dfee2236f697ab1d5e2771c2e5c248495fa0d + +COCOAPODS: 0.38.2 diff --git a/Pods/Headers/Private/PureLayout/ALView+PureLayout.h b/Pods/Headers/Private/PureLayout/ALView+PureLayout.h new file mode 120000 index 0000000..ac489e2 --- /dev/null +++ b/Pods/Headers/Private/PureLayout/ALView+PureLayout.h @@ -0,0 +1 @@ +../../../PureLayout/PureLayout/PureLayout/ALView+PureLayout.h \ No newline at end of file diff --git a/Pods/Headers/Private/PureLayout/NSArray+PureLayout.h b/Pods/Headers/Private/PureLayout/NSArray+PureLayout.h new file mode 120000 index 0000000..76395e6 --- /dev/null +++ b/Pods/Headers/Private/PureLayout/NSArray+PureLayout.h @@ -0,0 +1 @@ +../../../PureLayout/PureLayout/PureLayout/NSArray+PureLayout.h \ No newline at end of file diff --git a/Pods/Headers/Private/PureLayout/NSLayoutConstraint+PureLayout.h b/Pods/Headers/Private/PureLayout/NSLayoutConstraint+PureLayout.h new file mode 120000 index 0000000..a2afdda --- /dev/null +++ b/Pods/Headers/Private/PureLayout/NSLayoutConstraint+PureLayout.h @@ -0,0 +1 @@ +../../../PureLayout/PureLayout/PureLayout/NSLayoutConstraint+PureLayout.h \ No newline at end of file diff --git a/Pods/Headers/Private/PureLayout/PureLayout+Internal.h b/Pods/Headers/Private/PureLayout/PureLayout+Internal.h new file mode 120000 index 0000000..972a4ee --- /dev/null +++ b/Pods/Headers/Private/PureLayout/PureLayout+Internal.h @@ -0,0 +1 @@ +../../../PureLayout/PureLayout/PureLayout/PureLayout+Internal.h \ No newline at end of file diff --git a/Pods/Headers/Private/PureLayout/PureLayout.h b/Pods/Headers/Private/PureLayout/PureLayout.h new file mode 120000 index 0000000..616d281 --- /dev/null +++ b/Pods/Headers/Private/PureLayout/PureLayout.h @@ -0,0 +1 @@ +../../../PureLayout/PureLayout/PureLayout/PureLayout.h \ No newline at end of file diff --git a/Pods/Headers/Private/PureLayout/PureLayoutDefines.h b/Pods/Headers/Private/PureLayout/PureLayoutDefines.h new file mode 120000 index 0000000..4a67193 --- /dev/null +++ b/Pods/Headers/Private/PureLayout/PureLayoutDefines.h @@ -0,0 +1 @@ +../../../PureLayout/PureLayout/PureLayout/PureLayoutDefines.h \ No newline at end of file diff --git a/Pods/Manifest.lock b/Pods/Manifest.lock new file mode 100644 index 0000000..c5a36c7 --- /dev/null +++ b/Pods/Manifest.lock @@ -0,0 +1,10 @@ +PODS: + - PureLayout (3.0.0) + +DEPENDENCIES: + - PureLayout + +SPEC CHECKSUMS: + PureLayout: 270dfee2236f697ab1d5e2771c2e5c248495fa0d + +COCOAPODS: 0.38.2 diff --git a/Pods/Pods.xcodeproj/project.pbxproj b/Pods/Pods.xcodeproj/project.pbxproj new file mode 100644 index 0000000..4b44319 --- /dev/null +++ b/Pods/Pods.xcodeproj/project.pbxproj @@ -0,0 +1,532 @@ +// !$*UTF8*$! +{ + archiveVersion = 1; + classes = { + }; + objectVersion = 46; + objects = { + +/* Begin PBXBuildFile section */ + 2241ABC30538E46F17BC59AFC645B6C5 /* NSArray+PureLayout.m in Sources */ = {isa = PBXBuildFile; fileRef = 191E1C6095DA6537B3B9AD63F2DABA12 /* NSArray+PureLayout.m */; }; + 38792B4D4276C59B21ACF9B4DE6ED4F5 /* PureLayout+Internal.h in Headers */ = {isa = PBXBuildFile; fileRef = DAFA4BCE4B185A782DD016F84B3BE0CF /* PureLayout+Internal.h */; settings = {ATTRIBUTES = (Public, ); }; }; + 40C283F04408D7C74CB6D9966B4CE10E /* ALView+PureLayout.m in Sources */ = {isa = PBXBuildFile; fileRef = 6FDCF9208FAF09CC79F2DA4FA5683C82 /* ALView+PureLayout.m */; }; + 5EFAEC887045E3038CBA406FC9C48C82 /* Pods-umbrella.h in Headers */ = {isa = PBXBuildFile; fileRef = D3B8F899423E15C997E14FB2404791C6 /* Pods-umbrella.h */; settings = {ATTRIBUTES = (Public, ); }; }; + 6354BF1C514445C33F9B65DD18205535 /* NSArray+PureLayout.h in Headers */ = {isa = PBXBuildFile; fileRef = 913E7306AD4E255661D418473382CF54 /* NSArray+PureLayout.h */; settings = {ATTRIBUTES = (Public, ); }; }; + 6837A6326B4A297F0F37B60F67C0706B /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 9011C520EFA96D78421817354D237D35 /* Foundation.framework */; }; + 7C6672FF5BC14E5A632F38FBCF4D84F6 /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 9011C520EFA96D78421817354D237D35 /* Foundation.framework */; }; + 8A42E3EC15CA6EFC7A14FF66419B4E0A /* NSLayoutConstraint+PureLayout.m in Sources */ = {isa = PBXBuildFile; fileRef = 97F5A0160929E8154C67BBC4B5A91B5C /* NSLayoutConstraint+PureLayout.m */; }; + 8FB29797E35802BE65A888432368F471 /* PureLayout-umbrella.h in Headers */ = {isa = PBXBuildFile; fileRef = 17DA7E900B1E7945C8B8CE59D225F706 /* PureLayout-umbrella.h */; settings = {ATTRIBUTES = (Public, ); }; }; + 98DE61629DE81688A6D460FF03DD172A /* PureLayout.h in Headers */ = {isa = PBXBuildFile; fileRef = 6E05779740DB7A4882324BB0CC77FE83 /* PureLayout.h */; settings = {ATTRIBUTES = (Public, ); }; }; + A9DC2F99B25B83F8896D0DEF1D5709D0 /* Pods-dummy.m in Sources */ = {isa = PBXBuildFile; fileRef = 4B29C2EEF0D874EC57444010B89A6DD3 /* Pods-dummy.m */; }; + BEEF2FF4434A311B51CCAEA2D0BC4167 /* PureLayout-dummy.m in Sources */ = {isa = PBXBuildFile; fileRef = 7ADC5572B76BA1CB325993B5EB36DD36 /* PureLayout-dummy.m */; }; + C07804D5CAE775845193B0BDEAE8153A /* ALView+PureLayout.h in Headers */ = {isa = PBXBuildFile; fileRef = 13DC162AF7BEBCA584CAF9D9CEAD8319 /* ALView+PureLayout.h */; settings = {ATTRIBUTES = (Public, ); }; }; + E822E9813D45FF34F11862731B65F4D7 /* NSLayoutConstraint+PureLayout.h in Headers */ = {isa = PBXBuildFile; fileRef = 9CD3AB8195F74BFC43D6997F61F6F298 /* NSLayoutConstraint+PureLayout.h */; settings = {ATTRIBUTES = (Public, ); }; }; + F9A3864238BEAF7F67E75EF7417D7AF4 /* PureLayoutDefines.h in Headers */ = {isa = PBXBuildFile; fileRef = 0FBC3E333821E19620FAC1463F61C533 /* PureLayoutDefines.h */; settings = {ATTRIBUTES = (Public, ); }; }; +/* End PBXBuildFile section */ + +/* Begin PBXContainerItemProxy section */ + D4BE9AC9A09AF52392290EC0CA80E1A2 /* PBXContainerItemProxy */ = { + isa = PBXContainerItemProxy; + containerPortal = D41D8CD98F00B204E9800998ECF8427E /* Project object */; + proxyType = 1; + remoteGlobalIDString = 8240A687A12B3496C485DFBEB80E79E2; + remoteInfo = PureLayout; + }; +/* End PBXContainerItemProxy section */ + +/* Begin PBXFileReference section */ + 0FBC3E333821E19620FAC1463F61C533 /* PureLayoutDefines.h */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.c.h; name = PureLayoutDefines.h; path = PureLayout/PureLayout/PureLayoutDefines.h; sourceTree = ""; }; + 13DC162AF7BEBCA584CAF9D9CEAD8319 /* ALView+PureLayout.h */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.c.h; name = "ALView+PureLayout.h"; path = "PureLayout/PureLayout/ALView+PureLayout.h"; sourceTree = ""; }; + 17DA7E900B1E7945C8B8CE59D225F706 /* PureLayout-umbrella.h */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.c.h; path = "PureLayout-umbrella.h"; sourceTree = ""; }; + 191E1C6095DA6537B3B9AD63F2DABA12 /* NSArray+PureLayout.m */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.c.objc; name = "NSArray+PureLayout.m"; path = "PureLayout/PureLayout/NSArray+PureLayout.m"; sourceTree = ""; }; + 25EB15ADDC91D3318D94A842E4FC598D /* Pods.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; path = Pods.debug.xcconfig; sourceTree = ""; }; + 2B98C72313E9B08E15E4970F6A8BB5B6 /* PureLayout.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; path = PureLayout.xcconfig; sourceTree = ""; }; + 34BE0BA12096455AB6760CFDF1005D58 /* PureLayout.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = PureLayout.framework; sourceTree = BUILT_PRODUCTS_DIR; }; + 37B11DEC4162936E069BC7FEF119B09C /* PureLayout.modulemap */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = "sourcecode.module-map"; path = PureLayout.modulemap; sourceTree = ""; }; + 4B29C2EEF0D874EC57444010B89A6DD3 /* Pods-dummy.m */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.c.objc; path = "Pods-dummy.m"; sourceTree = ""; }; + 59D9DEAEBEB4B4AE79B77C4D1EEF3DAE /* Info.plist */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; + 6E05779740DB7A4882324BB0CC77FE83 /* PureLayout.h */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.c.h; name = PureLayout.h; path = PureLayout/PureLayout/PureLayout.h; sourceTree = ""; }; + 6FDCF9208FAF09CC79F2DA4FA5683C82 /* ALView+PureLayout.m */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.c.objc; name = "ALView+PureLayout.m"; path = "PureLayout/PureLayout/ALView+PureLayout.m"; sourceTree = ""; }; + 79A9DEDC89FE8336BF5FEDAAF75BF7FC /* Pods.modulemap */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = "sourcecode.module-map"; path = Pods.modulemap; sourceTree = ""; }; + 7ADC5572B76BA1CB325993B5EB36DD36 /* PureLayout-dummy.m */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.c.objc; path = "PureLayout-dummy.m"; sourceTree = ""; }; + 87B213035BAC5F75386F62D3C75D2342 /* Pods-acknowledgements.plist */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.plist.xml; path = "Pods-acknowledgements.plist"; sourceTree = ""; }; + 9011C520EFA96D78421817354D237D35 /* Foundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Foundation.framework; path = Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS8.3.sdk/System/Library/Frameworks/Foundation.framework; sourceTree = DEVELOPER_DIR; }; + 913E7306AD4E255661D418473382CF54 /* NSArray+PureLayout.h */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.c.h; name = "NSArray+PureLayout.h"; path = "PureLayout/PureLayout/NSArray+PureLayout.h"; sourceTree = ""; }; + 97F5A0160929E8154C67BBC4B5A91B5C /* NSLayoutConstraint+PureLayout.m */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.c.objc; name = "NSLayoutConstraint+PureLayout.m"; path = "PureLayout/PureLayout/NSLayoutConstraint+PureLayout.m"; sourceTree = ""; }; + 9CD3AB8195F74BFC43D6997F61F6F298 /* NSLayoutConstraint+PureLayout.h */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.c.h; name = "NSLayoutConstraint+PureLayout.h"; path = "PureLayout/PureLayout/NSLayoutConstraint+PureLayout.h"; sourceTree = ""; }; + B870EF585C629C2B8EFC01EFA066E0AC /* Pods.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods.framework; sourceTree = BUILT_PRODUCTS_DIR; }; + BA6428E9F66FD5A23C0A2E06ED26CD2F /* Podfile */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text; name = Podfile; path = ../Podfile; sourceTree = SOURCE_ROOT; xcLanguageSpecificationIdentifier = xcode.lang.ruby; }; + CBC0F7C552B739C909B650A0F42F7F38 /* Pods-resources.sh */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.script.sh; path = "Pods-resources.sh"; sourceTree = ""; }; + CC4882E403503DE9288AF3969E260251 /* PureLayout-Private.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; path = "PureLayout-Private.xcconfig"; sourceTree = ""; }; + D0405803033A2A777B8E4DFA0C1800ED /* Pods-acknowledgements.markdown */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text; path = "Pods-acknowledgements.markdown"; sourceTree = ""; }; + D3B8F899423E15C997E14FB2404791C6 /* Pods-umbrella.h */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.c.h; path = "Pods-umbrella.h"; sourceTree = ""; }; + D77F20524604100E192667662A8784A5 /* Pods.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; path = Pods.release.xcconfig; sourceTree = ""; }; + DAFA4BCE4B185A782DD016F84B3BE0CF /* PureLayout+Internal.h */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.c.h; name = "PureLayout+Internal.h"; path = "PureLayout/PureLayout/PureLayout+Internal.h"; sourceTree = ""; }; + E608DBDD091C6DAAF7133EFDA8960D3A /* PureLayout-prefix.pch */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.c.h; path = "PureLayout-prefix.pch"; sourceTree = ""; }; + E7F21354943D9F42A70697D5A5EF72E9 /* Pods-frameworks.sh */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.script.sh; path = "Pods-frameworks.sh"; sourceTree = ""; }; + E8446514FBAD26C0E18F24A5715AEF67 /* Info.plist */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; +/* End PBXFileReference section */ + +/* Begin PBXFrameworksBuildPhase section */ + 52E761D0B069DCD4C6E2F74FA447C130 /* Frameworks */ = { + isa = PBXFrameworksBuildPhase; + buildActionMask = 2147483647; + files = ( + 6837A6326B4A297F0F37B60F67C0706B /* Foundation.framework in Frameworks */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; + 8D982826564F33040944F955F4866DBD /* Frameworks */ = { + isa = PBXFrameworksBuildPhase; + buildActionMask = 2147483647; + files = ( + 7C6672FF5BC14E5A632F38FBCF4D84F6 /* Foundation.framework in Frameworks */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXFrameworksBuildPhase section */ + +/* Begin PBXGroup section */ + 53F661C0CA7190D2CF05023FB33D61E4 /* iOS */ = { + isa = PBXGroup; + children = ( + 9011C520EFA96D78421817354D237D35 /* Foundation.framework */, + ); + name = iOS; + sourceTree = ""; + }; + 56E5F5118E3951F2C822D54DF77B17DB /* Support Files */ = { + isa = PBXGroup; + children = ( + 59D9DEAEBEB4B4AE79B77C4D1EEF3DAE /* Info.plist */, + 37B11DEC4162936E069BC7FEF119B09C /* PureLayout.modulemap */, + 2B98C72313E9B08E15E4970F6A8BB5B6 /* PureLayout.xcconfig */, + CC4882E403503DE9288AF3969E260251 /* PureLayout-Private.xcconfig */, + 7ADC5572B76BA1CB325993B5EB36DD36 /* PureLayout-dummy.m */, + E608DBDD091C6DAAF7133EFDA8960D3A /* PureLayout-prefix.pch */, + 17DA7E900B1E7945C8B8CE59D225F706 /* PureLayout-umbrella.h */, + ); + name = "Support Files"; + path = "../Target Support Files/PureLayout"; + sourceTree = ""; + }; + 75D98FF52E597A11900E131B6C4E1ADA /* Pods */ = { + isa = PBXGroup; + children = ( + E8446514FBAD26C0E18F24A5715AEF67 /* Info.plist */, + 79A9DEDC89FE8336BF5FEDAAF75BF7FC /* Pods.modulemap */, + D0405803033A2A777B8E4DFA0C1800ED /* Pods-acknowledgements.markdown */, + 87B213035BAC5F75386F62D3C75D2342 /* Pods-acknowledgements.plist */, + 4B29C2EEF0D874EC57444010B89A6DD3 /* Pods-dummy.m */, + E7F21354943D9F42A70697D5A5EF72E9 /* Pods-frameworks.sh */, + CBC0F7C552B739C909B650A0F42F7F38 /* Pods-resources.sh */, + D3B8F899423E15C997E14FB2404791C6 /* Pods-umbrella.h */, + 25EB15ADDC91D3318D94A842E4FC598D /* Pods.debug.xcconfig */, + D77F20524604100E192667662A8784A5 /* Pods.release.xcconfig */, + ); + name = Pods; + path = "Target Support Files/Pods"; + sourceTree = ""; + }; + 7DB346D0F39D3F0E887471402A8071AB = { + isa = PBXGroup; + children = ( + BA6428E9F66FD5A23C0A2E06ED26CD2F /* Podfile */, + BC3CA7F9E30CC8F7E2DD044DD34432FC /* Frameworks */, + A2FDD832DA64F35B104DD4C55A31BF8E /* Pods */, + CCA510CFBEA2D207524CDA0D73C3B561 /* Products */, + B7B80995527643776607AFFA75B91E24 /* Targets Support Files */, + ); + sourceTree = ""; + }; + A2FDD832DA64F35B104DD4C55A31BF8E /* Pods */ = { + isa = PBXGroup; + children = ( + FB712A69E0D41FEA99EB1907FFD5357A /* PureLayout */, + ); + name = Pods; + sourceTree = ""; + }; + B7B80995527643776607AFFA75B91E24 /* Targets Support Files */ = { + isa = PBXGroup; + children = ( + 75D98FF52E597A11900E131B6C4E1ADA /* Pods */, + ); + name = "Targets Support Files"; + sourceTree = ""; + }; + BC3CA7F9E30CC8F7E2DD044DD34432FC /* Frameworks */ = { + isa = PBXGroup; + children = ( + 53F661C0CA7190D2CF05023FB33D61E4 /* iOS */, + ); + name = Frameworks; + sourceTree = ""; + }; + CCA510CFBEA2D207524CDA0D73C3B561 /* Products */ = { + isa = PBXGroup; + children = ( + B870EF585C629C2B8EFC01EFA066E0AC /* Pods.framework */, + 34BE0BA12096455AB6760CFDF1005D58 /* PureLayout.framework */, + ); + name = Products; + sourceTree = ""; + }; + FB712A69E0D41FEA99EB1907FFD5357A /* PureLayout */ = { + isa = PBXGroup; + children = ( + 13DC162AF7BEBCA584CAF9D9CEAD8319 /* ALView+PureLayout.h */, + 6FDCF9208FAF09CC79F2DA4FA5683C82 /* ALView+PureLayout.m */, + 913E7306AD4E255661D418473382CF54 /* NSArray+PureLayout.h */, + 191E1C6095DA6537B3B9AD63F2DABA12 /* NSArray+PureLayout.m */, + 9CD3AB8195F74BFC43D6997F61F6F298 /* NSLayoutConstraint+PureLayout.h */, + 97F5A0160929E8154C67BBC4B5A91B5C /* NSLayoutConstraint+PureLayout.m */, + 6E05779740DB7A4882324BB0CC77FE83 /* PureLayout.h */, + DAFA4BCE4B185A782DD016F84B3BE0CF /* PureLayout+Internal.h */, + 0FBC3E333821E19620FAC1463F61C533 /* PureLayoutDefines.h */, + 56E5F5118E3951F2C822D54DF77B17DB /* Support Files */, + ); + path = PureLayout; + sourceTree = ""; + }; +/* End PBXGroup section */ + +/* Begin PBXHeadersBuildPhase section */ + 0C97D2361202E0C0803501F6EFE50376 /* Headers */ = { + isa = PBXHeadersBuildPhase; + buildActionMask = 2147483647; + files = ( + 5EFAEC887045E3038CBA406FC9C48C82 /* Pods-umbrella.h in Headers */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; + D6A8EB0B19838A8E6F05524B3A33BF15 /* Headers */ = { + isa = PBXHeadersBuildPhase; + buildActionMask = 2147483647; + files = ( + C07804D5CAE775845193B0BDEAE8153A /* ALView+PureLayout.h in Headers */, + 6354BF1C514445C33F9B65DD18205535 /* NSArray+PureLayout.h in Headers */, + E822E9813D45FF34F11862731B65F4D7 /* NSLayoutConstraint+PureLayout.h in Headers */, + 38792B4D4276C59B21ACF9B4DE6ED4F5 /* PureLayout+Internal.h in Headers */, + 8FB29797E35802BE65A888432368F471 /* PureLayout-umbrella.h in Headers */, + 98DE61629DE81688A6D460FF03DD172A /* PureLayout.h in Headers */, + F9A3864238BEAF7F67E75EF7417D7AF4 /* PureLayoutDefines.h in Headers */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXHeadersBuildPhase section */ + +/* Begin PBXNativeTarget section */ + 057BC0C6AD434A55BEB3F883C422AF4B /* Pods */ = { + isa = PBXNativeTarget; + buildConfigurationList = D2FB98E34FE23B33951F2DB1E322484F /* Build configuration list for PBXNativeTarget "Pods" */; + buildPhases = ( + 3BBEA412E86660B28BB741848540178E /* Sources */, + 52E761D0B069DCD4C6E2F74FA447C130 /* Frameworks */, + 0C97D2361202E0C0803501F6EFE50376 /* Headers */, + ); + buildRules = ( + ); + dependencies = ( + B499FB60A50262DAF978C33F6DCCE2F5 /* PBXTargetDependency */, + ); + name = Pods; + productName = Pods; + productReference = B870EF585C629C2B8EFC01EFA066E0AC /* Pods.framework */; + productType = "com.apple.product-type.framework"; + }; + 8240A687A12B3496C485DFBEB80E79E2 /* PureLayout */ = { + isa = PBXNativeTarget; + buildConfigurationList = 29946541803109559D5B69F86E5F2398 /* Build configuration list for PBXNativeTarget "PureLayout" */; + buildPhases = ( + ABBB6E4260C5266FB8BA4EC731A8D281 /* Sources */, + 8D982826564F33040944F955F4866DBD /* Frameworks */, + D6A8EB0B19838A8E6F05524B3A33BF15 /* Headers */, + ); + buildRules = ( + ); + dependencies = ( + ); + name = PureLayout; + productName = PureLayout; + productReference = 34BE0BA12096455AB6760CFDF1005D58 /* PureLayout.framework */; + productType = "com.apple.product-type.framework"; + }; +/* End PBXNativeTarget section */ + +/* Begin PBXProject section */ + D41D8CD98F00B204E9800998ECF8427E /* Project object */ = { + isa = PBXProject; + attributes = { + LastSwiftUpdateCheck = 0700; + LastUpgradeCheck = 0700; + }; + buildConfigurationList = 2D8E8EC45A3A1A1D94AE762CB5028504 /* Build configuration list for PBXProject "Pods" */; + compatibilityVersion = "Xcode 3.2"; + developmentRegion = English; + hasScannedForEncodings = 0; + knownRegions = ( + en, + ); + mainGroup = 7DB346D0F39D3F0E887471402A8071AB; + productRefGroup = CCA510CFBEA2D207524CDA0D73C3B561 /* Products */; + projectDirPath = ""; + projectRoot = ""; + targets = ( + 057BC0C6AD434A55BEB3F883C422AF4B /* Pods */, + 8240A687A12B3496C485DFBEB80E79E2 /* PureLayout */, + ); + }; +/* End PBXProject section */ + +/* Begin PBXSourcesBuildPhase section */ + 3BBEA412E86660B28BB741848540178E /* Sources */ = { + isa = PBXSourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + A9DC2F99B25B83F8896D0DEF1D5709D0 /* Pods-dummy.m in Sources */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; + ABBB6E4260C5266FB8BA4EC731A8D281 /* Sources */ = { + isa = PBXSourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + 40C283F04408D7C74CB6D9966B4CE10E /* ALView+PureLayout.m in Sources */, + 2241ABC30538E46F17BC59AFC645B6C5 /* NSArray+PureLayout.m in Sources */, + 8A42E3EC15CA6EFC7A14FF66419B4E0A /* NSLayoutConstraint+PureLayout.m in Sources */, + BEEF2FF4434A311B51CCAEA2D0BC4167 /* PureLayout-dummy.m in Sources */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXSourcesBuildPhase section */ + +/* Begin PBXTargetDependency section */ + B499FB60A50262DAF978C33F6DCCE2F5 /* PBXTargetDependency */ = { + isa = PBXTargetDependency; + name = PureLayout; + target = 8240A687A12B3496C485DFBEB80E79E2 /* PureLayout */; + targetProxy = D4BE9AC9A09AF52392290EC0CA80E1A2 /* PBXContainerItemProxy */; + }; +/* End PBXTargetDependency section */ + +/* Begin XCBuildConfiguration section */ + 116000359465EEA84BEB4A3D54B09C44 /* Debug */ = { + isa = XCBuildConfiguration; + baseConfigurationReference = 25EB15ADDC91D3318D94A842E4FC598D /* Pods.debug.xcconfig */; + buildSettings = { + "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; + CURRENT_PROJECT_VERSION = 1; + DEFINES_MODULE = YES; + DYLIB_COMPATIBILITY_VERSION = 1; + DYLIB_CURRENT_VERSION = 1; + DYLIB_INSTALL_NAME_BASE = "@rpath"; + ENABLE_STRICT_OBJC_MSGSEND = YES; + INFOPLIST_FILE = "Target Support Files/Pods/Info.plist"; + INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; + IPHONEOS_DEPLOYMENT_TARGET = 8.0; + LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; + MODULEMAP_FILE = "Target Support Files/Pods/Pods.modulemap"; + MTL_ENABLE_DEBUG_INFO = YES; + OTHER_LDFLAGS = ""; + OTHER_LIBTOOLFLAGS = ""; + PODS_ROOT = "$(SRCROOT)"; + PRODUCT_NAME = Pods; + SDKROOT = iphoneos; + SKIP_INSTALL = YES; + TARGETED_DEVICE_FAMILY = "1,2"; + VERSIONING_SYSTEM = "apple-generic"; + VERSION_INFO_PREFIX = ""; + }; + name = Debug; + }; + 4B0B1BF0388DEA06DE8DF1B21F4B00AB /* Release */ = { + isa = XCBuildConfiguration; + baseConfigurationReference = CC4882E403503DE9288AF3969E260251 /* PureLayout-Private.xcconfig */; + buildSettings = { + "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; + CURRENT_PROJECT_VERSION = 3.0.0; + DEFINES_MODULE = YES; + DYLIB_COMPATIBILITY_VERSION = 3; + DYLIB_CURRENT_VERSION = "$(CURRENT_PROJECT_VERSION)"; + DYLIB_INSTALL_NAME_BASE = "@rpath"; + ENABLE_STRICT_OBJC_MSGSEND = YES; + GCC_PREFIX_HEADER = "Target Support Files/PureLayout/PureLayout-prefix.pch"; + INFOPLIST_FILE = "Target Support Files/PureLayout/Info.plist"; + INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; + IPHONEOS_DEPLOYMENT_TARGET = 8.0; + LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; + MODULEMAP_FILE = "Target Support Files/PureLayout/PureLayout.modulemap"; + MTL_ENABLE_DEBUG_INFO = NO; + PRODUCT_NAME = PureLayout; + SDKROOT = iphoneos; + SKIP_INSTALL = YES; + TARGETED_DEVICE_FAMILY = "1,2"; + VERSIONING_SYSTEM = "apple-generic"; + VERSION_INFO_PREFIX = ""; + }; + name = Release; + }; + A70CDAD61F90AC503C7D04CC22DA2923 /* Debug */ = { + isa = XCBuildConfiguration; + buildSettings = { + ALWAYS_SEARCH_USER_PATHS = NO; + CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; + CLANG_CXX_LIBRARY = "libc++"; + CLANG_ENABLE_MODULES = YES; + CLANG_ENABLE_OBJC_ARC = YES; + CLANG_WARN_BOOL_CONVERSION = YES; + CLANG_WARN_CONSTANT_CONVERSION = YES; + CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES; + CLANG_WARN_EMPTY_BODY = YES; + CLANG_WARN_ENUM_CONVERSION = YES; + CLANG_WARN_INT_CONVERSION = YES; + CLANG_WARN_OBJC_ROOT_CLASS = YES; + CLANG_WARN_UNREACHABLE_CODE = YES; + CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; + COPY_PHASE_STRIP = NO; + GCC_C_LANGUAGE_STANDARD = gnu99; + GCC_DYNAMIC_NO_PIC = NO; + GCC_OPTIMIZATION_LEVEL = 0; + GCC_PREPROCESSOR_DEFINITIONS = ( + "DEBUG=1", + "$(inherited)", + ); + GCC_SYMBOLS_PRIVATE_EXTERN = NO; + GCC_WARN_64_TO_32_BIT_CONVERSION = YES; + GCC_WARN_ABOUT_RETURN_TYPE = YES; + GCC_WARN_UNDECLARED_SELECTOR = YES; + GCC_WARN_UNINITIALIZED_AUTOS = YES; + GCC_WARN_UNUSED_FUNCTION = YES; + GCC_WARN_UNUSED_VARIABLE = YES; + IPHONEOS_DEPLOYMENT_TARGET = 8.0; + ONLY_ACTIVE_ARCH = YES; + STRIP_INSTALLED_PRODUCT = NO; + SYMROOT = "${SRCROOT}/../build"; + }; + name = Debug; + }; + D7F9E64735A4A34EA962C8B922037D79 /* Release */ = { + isa = XCBuildConfiguration; + baseConfigurationReference = D77F20524604100E192667662A8784A5 /* Pods.release.xcconfig */; + buildSettings = { + "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; + CURRENT_PROJECT_VERSION = 1; + DEFINES_MODULE = YES; + DYLIB_COMPATIBILITY_VERSION = 1; + DYLIB_CURRENT_VERSION = 1; + DYLIB_INSTALL_NAME_BASE = "@rpath"; + ENABLE_STRICT_OBJC_MSGSEND = YES; + INFOPLIST_FILE = "Target Support Files/Pods/Info.plist"; + INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; + IPHONEOS_DEPLOYMENT_TARGET = 8.0; + LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; + MODULEMAP_FILE = "Target Support Files/Pods/Pods.modulemap"; + MTL_ENABLE_DEBUG_INFO = NO; + OTHER_LDFLAGS = ""; + OTHER_LIBTOOLFLAGS = ""; + PODS_ROOT = "$(SRCROOT)"; + PRODUCT_NAME = Pods; + SDKROOT = iphoneos; + SKIP_INSTALL = YES; + TARGETED_DEVICE_FAMILY = "1,2"; + VERSIONING_SYSTEM = "apple-generic"; + VERSION_INFO_PREFIX = ""; + }; + name = Release; + }; + DB5C373F43D2E2027D3302E3EB9783D7 /* Debug */ = { + isa = XCBuildConfiguration; + baseConfigurationReference = CC4882E403503DE9288AF3969E260251 /* PureLayout-Private.xcconfig */; + buildSettings = { + "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; + CURRENT_PROJECT_VERSION = 3.0.0; + DEFINES_MODULE = YES; + DYLIB_COMPATIBILITY_VERSION = 3; + DYLIB_CURRENT_VERSION = "$(CURRENT_PROJECT_VERSION)"; + DYLIB_INSTALL_NAME_BASE = "@rpath"; + ENABLE_STRICT_OBJC_MSGSEND = YES; + GCC_PREFIX_HEADER = "Target Support Files/PureLayout/PureLayout-prefix.pch"; + INFOPLIST_FILE = "Target Support Files/PureLayout/Info.plist"; + INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; + IPHONEOS_DEPLOYMENT_TARGET = 8.0; + LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; + MODULEMAP_FILE = "Target Support Files/PureLayout/PureLayout.modulemap"; + MTL_ENABLE_DEBUG_INFO = YES; + PRODUCT_NAME = PureLayout; + SDKROOT = iphoneos; + SKIP_INSTALL = YES; + TARGETED_DEVICE_FAMILY = "1,2"; + VERSIONING_SYSTEM = "apple-generic"; + VERSION_INFO_PREFIX = ""; + }; + name = Debug; + }; + FB45FFD90572718D82AB9092B750F0CA /* Release */ = { + isa = XCBuildConfiguration; + buildSettings = { + ALWAYS_SEARCH_USER_PATHS = NO; + CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; + CLANG_CXX_LIBRARY = "libc++"; + CLANG_ENABLE_MODULES = YES; + CLANG_ENABLE_OBJC_ARC = YES; + CLANG_WARN_BOOL_CONVERSION = YES; + CLANG_WARN_CONSTANT_CONVERSION = YES; + CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES; + CLANG_WARN_EMPTY_BODY = YES; + CLANG_WARN_ENUM_CONVERSION = YES; + CLANG_WARN_INT_CONVERSION = YES; + CLANG_WARN_OBJC_ROOT_CLASS = YES; + CLANG_WARN_UNREACHABLE_CODE = YES; + CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; + COPY_PHASE_STRIP = YES; + ENABLE_NS_ASSERTIONS = NO; + GCC_C_LANGUAGE_STANDARD = gnu99; + GCC_PREPROCESSOR_DEFINITIONS = "RELEASE=1"; + GCC_WARN_64_TO_32_BIT_CONVERSION = YES; + GCC_WARN_ABOUT_RETURN_TYPE = YES; + GCC_WARN_UNDECLARED_SELECTOR = YES; + GCC_WARN_UNINITIALIZED_AUTOS = YES; + GCC_WARN_UNUSED_FUNCTION = YES; + GCC_WARN_UNUSED_VARIABLE = YES; + IPHONEOS_DEPLOYMENT_TARGET = 8.0; + STRIP_INSTALLED_PRODUCT = NO; + SYMROOT = "${SRCROOT}/../build"; + VALIDATE_PRODUCT = YES; + }; + name = Release; + }; +/* End XCBuildConfiguration section */ + +/* Begin XCConfigurationList section */ + 29946541803109559D5B69F86E5F2398 /* Build configuration list for PBXNativeTarget "PureLayout" */ = { + isa = XCConfigurationList; + buildConfigurations = ( + DB5C373F43D2E2027D3302E3EB9783D7 /* Debug */, + 4B0B1BF0388DEA06DE8DF1B21F4B00AB /* Release */, + ); + defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; + }; + 2D8E8EC45A3A1A1D94AE762CB5028504 /* Build configuration list for PBXProject "Pods" */ = { + isa = XCConfigurationList; + buildConfigurations = ( + A70CDAD61F90AC503C7D04CC22DA2923 /* Debug */, + FB45FFD90572718D82AB9092B750F0CA /* Release */, + ); + defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; + }; + D2FB98E34FE23B33951F2DB1E322484F /* Build configuration list for PBXNativeTarget "Pods" */ = { + isa = XCConfigurationList; + buildConfigurations = ( + 116000359465EEA84BEB4A3D54B09C44 /* Debug */, + D7F9E64735A4A34EA962C8B922037D79 /* Release */, + ); + defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; + }; +/* End XCConfigurationList section */ + }; + rootObject = D41D8CD98F00B204E9800998ECF8427E /* Project object */; +} diff --git a/Pods/PureLayout/LICENSE b/Pods/PureLayout/LICENSE new file mode 100755 index 0000000..5396bc0 --- /dev/null +++ b/Pods/PureLayout/LICENSE @@ -0,0 +1,9 @@ +This code is distributed under the terms and conditions of the MIT license. + +Copyright (c) 2014-2015 Tyler Fox + +Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. diff --git a/TableViewCellWithAutoLayout/PureLayout/ALView+PureLayout.h b/Pods/PureLayout/PureLayout/PureLayout/ALView+PureLayout.h similarity index 68% rename from TableViewCellWithAutoLayout/PureLayout/ALView+PureLayout.h rename to Pods/PureLayout/PureLayout/PureLayout/ALView+PureLayout.h index ae74922..525e7aa 100755 --- a/TableViewCellWithAutoLayout/PureLayout/ALView+PureLayout.h +++ b/Pods/PureLayout/PureLayout/PureLayout/ALView+PureLayout.h @@ -1,6 +1,5 @@ // // ALView+PureLayout.h -// v2.0.5 // https://github.com/smileyborg/PureLayout // // Copyright (c) 2012 Richard Turton @@ -30,7 +29,9 @@ #import "PureLayoutDefines.h" -#pragma mark - ALView+PureLayout +__PL_ASSUME_NONNULL_BEGIN + +#pragma mark ALView+PureLayout /** A category on UIView/NSView that provides a simple yet powerful interface for creating Auto Layout constraints. @@ -46,36 +47,14 @@ /** Initializes and returns a new view that does not convert the autoresizing mask into constraints. */ - (instancetype)initForAutoLayout; - -#pragma mark Create Constraints Without Installing - -/** Prevents constraints created in the given constraints block from being automatically installed (activated). - The constraints created from calls to the PureLayout API in the block are returned in a single array. */ -+ (NSArray *)autoCreateConstraintsWithoutInstalling:(ALConstraintsBlock)block; - - -#pragma mark Set Priority For Constraints - -/** Sets the constraint priority to the given value for all constraints created using the PureLayout API within the given constraints block. - NOTE: This method will have no effect (and will NOT set the priority) on constraints created or added without using the PureLayout API! */ -+ (void)autoSetPriority:(ALLayoutPriority)priority forConstraints:(ALConstraintsBlock)block; - - -#pragma mark Set Identifier For Constraints - -#if __PureLayout_MinBaseSDK_iOS_8_0 - -/** Sets the identifier for all constraints created using the PureLayout API within the given constraints block. - NOTE: This method will have no effect (and will NOT set the identifier) on constraints created or added without using the PureLayout API! */ -+ (void)autoSetIdentifier:(NSString *)identifier forConstraints:(ALConstraintsBlock)block; - -#endif /* __PureLayout_MinBaseSDK_iOS_8_0 */ +/** Configures an existing view to not convert the autoresizing mask into constraints and returns the view. */ +- (instancetype)configureForAutoLayout; #pragma mark Center & Align in Superview /** Centers the view in its superview. */ -- (NSArray *)autoCenterInSuperview; +- (__NSArray_of(NSLayoutConstraint *) *)autoCenterInSuperview; /** Aligns the view to the same axis of its superview. */ - (NSLayoutConstraint *)autoAlignAxisToSuperviewAxis:(ALAxis)axis; @@ -83,7 +62,7 @@ #if __PureLayout_MinBaseSDK_iOS_8_0 /** Centers the view in its superview's margins. Available in iOS 8.0 and later. */ -- (NSArray *)autoCenterInSuperviewMargins; +- (__NSArray_of(NSLayoutConstraint *) *)autoCenterInSuperviewMargins; /** Aligns the view to the corresponding margin axis of its superview. Available in iOS 8.0 and later. */ - (NSLayoutConstraint *)autoAlignAxisToSuperviewMarginAxis:(ALAxis)axis; @@ -102,11 +81,14 @@ /** Pins the given edge of the view to the same edge of its superview with an inset as a maximum or minimum. */ - (NSLayoutConstraint *)autoPinEdgeToSuperviewEdge:(ALEdge)edge withInset:(CGFloat)inset relation:(NSLayoutRelation)relation; +/** Pins the edges of the view to the edges of its superview. */ +- (__NSArray_of(NSLayoutConstraint *) *)autoPinEdgesToSuperviewEdges; + /** Pins the edges of the view to the edges of its superview with the given edge insets. */ -- (NSArray *)autoPinEdgesToSuperviewEdgesWithInsets:(ALEdgeInsets)insets; +- (__NSArray_of(NSLayoutConstraint *) *)autoPinEdgesToSuperviewEdgesWithInsets:(ALEdgeInsets)insets; /** Pins 3 of the 4 edges of the view to the edges of its superview with the given edge insets, excluding one edge. */ -- (NSArray *)autoPinEdgesToSuperviewEdgesWithInsets:(ALEdgeInsets)insets excludingEdge:(ALEdge)edge; +- (__NSArray_of(NSLayoutConstraint *) *)autoPinEdgesToSuperviewEdgesWithInsets:(ALEdgeInsets)insets excludingEdge:(ALEdge)edge; #if __PureLayout_MinBaseSDK_iOS_8_0 @@ -117,10 +99,10 @@ - (NSLayoutConstraint *)autoPinEdgeToSuperviewMargin:(ALEdge)edge relation:(NSLayoutRelation)relation; /** Pins the edges of the view to the margins of its superview. Available in iOS 8.0 and later. */ -- (NSArray *)autoPinEdgesToSuperviewMargins; +- (__NSArray_of(NSLayoutConstraint *) *)autoPinEdgesToSuperviewMargins; /** Pins 3 of the 4 edges of the view to the margins of its superview excluding one edge. Available in iOS 8.0 and later. */ -- (NSArray *)autoPinEdgesToSuperviewMarginsExcludingEdge:(ALEdge)edge; +- (__NSArray_of(NSLayoutConstraint *) *)autoPinEdgesToSuperviewMarginsExcludingEdge:(ALEdge)edge; #endif /* __PureLayout_MinBaseSDK_iOS_8_0 */ @@ -145,6 +127,9 @@ /** Aligns an axis of the view to the same axis of another view with an offset. */ - (NSLayoutConstraint *)autoAlignAxis:(ALAxis)axis toSameAxisOfView:(ALView *)otherView withOffset:(CGFloat)offset; +/** Aligns an axis of the view to the same axis of another view with a multiplier. */ +- (NSLayoutConstraint *)autoAlignAxis:(ALAxis)axis toSameAxisOfView:(ALView *)otherView withMultiplier:(CGFloat)multiplier; + #pragma mark Match Dimensions @@ -167,7 +152,7 @@ #pragma mark Set Dimensions /** Sets the view to a specific size. */ -- (NSArray *)autoSetDimensionsToSize:(CGSize)size; +- (__NSArray_of(NSLayoutConstraint *) *)autoSetDimensionsToSize:(CGSize)size; /** Sets the given dimension of the view to a specific size. */ - (NSLayoutConstraint *)autoSetDimension:(ALDimension)dimension toSize:(CGFloat)size; @@ -179,11 +164,11 @@ #pragma mark Set Content Compression Resistance & Hugging /** Sets the priority of content compression resistance for an axis. - NOTE: This method must be called from within the block passed into the method +[UIView autoSetPriority:forConstraints:] */ + NOTE: This method must be called from within the block passed into the method +[NSLayoutConstraint autoSetPriority:forConstraints:] */ - (void)autoSetContentCompressionResistancePriorityForAxis:(ALAxis)axis; /** Sets the priority of content hugging for an axis. - NOTE: This method must be called from within the block passed into the method +[UIView autoSetPriority:forConstraints:] */ + NOTE: This method must be called from within the block passed into the method +[NSLayoutConstraint autoSetPriority:forConstraints:] */ - (void)autoSetContentHuggingPriorityForAxis:(ALAxis)axis; @@ -223,31 +208,6 @@ #endif /* TARGET_OS_IPHONE */ - -#pragma mark Deprecated Methods - -/** DEPRECATED as of PureLayout v2.0.0. Retain a reference to and remove specific constraints instead, or recreate the view(s) entirely to remove all constraints. - Removes all explicit constraints that affect the view. - WARNING: Apple's constraint solver is not optimized for large-scale constraint removal; you may encounter major performance issues after using this method. - NOTE: This method preserves implicit constraints, such as intrinsic content size constraints, which you usually do not want to remove. */ -- (void)autoRemoveConstraintsAffectingView __attribute__((deprecated)); - -/** DEPRECATED as of PureLayout v2.0.0. Retain a reference to and remove specific constraints instead, or recreate the view(s) entirely to remove all constraints. - Removes all constraints that affect the view, optionally including implicit constraints. - WARNING: Apple's constraint solver is not optimized for large-scale constraint removal; you may encounter major performance issues after using this method. - NOTE: Implicit constraints are auto-generated lower priority constraints, and you usually do not want to remove these. */ -- (void)autoRemoveConstraintsAffectingViewIncludingImplicitConstraints:(BOOL)shouldRemoveImplicitConstraints __attribute__((deprecated)); - -/** DEPRECATED as of PureLayout v2.0.0. Retain a reference to and remove specific constraints instead, or recreate the view(s) entirely to remove all constraints. - Recursively removes all explicit constraints that affect the view and its subviews. - WARNING: Apple's constraint solver is not optimized for large-scale constraint removal; you may encounter major performance issues after using this method. - NOTE: This method preserves implicit constraints, such as intrinsic content size constraints, which you usually do not want to remove. */ -- (void)autoRemoveConstraintsAffectingViewAndSubviews __attribute__((deprecated)); - -/** DEPRECATED as of PureLayout v2.0.0. Retain a reference to and remove specific constraints instead, or recreate the view(s) entirely to remove all constraints. - Recursively removes all constraints from the view and its subviews, optionally including implicit constraints. - WARNING: Apple's constraint solver is not optimized for large-scale constraint removal; you may encounter major performance issues after using this method. - NOTE: Implicit constraints are auto-generated lower priority constraints, and you usually do not want to remove these. */ -- (void)autoRemoveConstraintsAffectingViewAndSubviewsIncludingImplicitConstraints:(BOOL)shouldRemoveImplicitConstraints __attribute__((deprecated)); - @end + +__PL_ASSUME_NONNULL_END diff --git a/TableViewCellWithAutoLayout/PureLayout/ALView+PureLayout.m b/Pods/PureLayout/PureLayout/PureLayout/ALView+PureLayout.m similarity index 70% rename from TableViewCellWithAutoLayout/PureLayout/ALView+PureLayout.m rename to Pods/PureLayout/PureLayout/PureLayout/ALView+PureLayout.m index 81817ca..dcc7309 100755 --- a/TableViewCellWithAutoLayout/PureLayout/ALView+PureLayout.m +++ b/Pods/PureLayout/PureLayout/PureLayout/ALView+PureLayout.m @@ -1,6 +1,5 @@ // // ALView+PureLayout.m -// v2.0.5 // https://github.com/smileyborg/PureLayout // // Copyright (c) 2012 Richard Turton @@ -62,199 +61,15 @@ - (instancetype)initForAutoLayout return self; } - -#pragma mark Create Constraints Without Installing - -/** - A global variable that stores a stack of arrays of constraints created without being immediately installed. - When executing a constraints block passed into the +[autoCreateConstraintsWithoutInstalling:] method, a new - mutable array is pushed onto this stack, and all constraints created with PureLayout in the block are added - to this array. When the block finishes executing, the array is popped off this stack. Automatic constraint - installation is prevented if this stack contains at least 1 array. - - NOTE: Access to this variable is not synchronized (and should only be done on the main thread). - */ -static NSMutableArray *_al_arraysOfCreatedConstraints = nil; - -/** - Accessor for the global state that stores arrays of constraints created without being installed. - */ -+ (NSMutableArray *)al_arraysOfCreatedConstraints -{ - if (!_al_arraysOfCreatedConstraints) { - _al_arraysOfCreatedConstraints = [NSMutableArray new]; - } - return _al_arraysOfCreatedConstraints; -} - -/** - Accessor for the current mutable array of constraints created without being immediately installed. - */ -+ (NSMutableArray *)al_currentArrayOfCreatedConstraints -{ - return [[self al_arraysOfCreatedConstraints] lastObject]; -} - -/** - Accessor for the global state that determines whether automatic constraint installation should be prevented. - */ -+ (BOOL)al_preventAutomaticConstraintInstallation -{ - return [[self al_arraysOfCreatedConstraints] count] > 0; -} - -/** - Prevents constraints created in the given constraints block from being automatically installed (activated). - The constraints created from calls to the PureLayout API in the block are returned in a single array. - - @param block A block of method calls to the PureLayout API that create constraints. - @return An array of the constraints that were created from calls to the PureLayout API inside the block. - */ -+ (NSArray *)autoCreateConstraintsWithoutInstalling:(ALConstraintsBlock)block -{ - NSAssert(block, @"The constraints block cannot be nil."); - NSArray *createdConstraints = nil; - if (block) { - [[self al_arraysOfCreatedConstraints] addObject:[NSMutableArray new]]; - block(); - createdConstraints = [self al_currentArrayOfCreatedConstraints]; - [[self al_arraysOfCreatedConstraints] removeLastObject]; - } - return createdConstraints; -} - - -#pragma mark Set Priority For Constraints - -/** - A global variable that stores a stack of layout priorities to set on constraints. - When executing a constraints block passed into the +[autoSetPriority:forConstraints:] method, the priority for - that call is pushed onto this stack, and when the block finishes executing, that priority is popped off this - stack. If this stack contains at least 1 priority, the priority at the top of the stack will be set for all - constraints created by this library (even if automatic constraint installation is being prevented). - NOTE: Access to this variable is not synchronized (and should only be done on the main thread). - */ -static NSMutableArray *_al_globalConstraintPriorities = nil; - -/** - Accessor for the global stack of layout priorities. - */ -+ (NSMutableArray *)al_globalConstraintPriorities -{ - if (!_al_globalConstraintPriorities) { - _al_globalConstraintPriorities = [NSMutableArray new]; - } - return _al_globalConstraintPriorities; -} - -/** - Returns the current layout priority to use for constraints. - When executing a constraints block passed into +[autoSetPriority:forConstraints:], this will return - the priority for the current block. Otherwise, the default Required priority is returned. - */ -+ (ALLayoutPriority)al_currentGlobalConstraintPriority -{ - NSMutableArray *globalConstraintPriorities = [self al_globalConstraintPriorities]; - if ([globalConstraintPriorities count] == 0) { - return ALLayoutPriorityRequired; - } - return [[globalConstraintPriorities lastObject] floatValue]; -} - -/** - Accessor for the global state that determines if we're currently in the scope of a priority constraints block. - */ -+ (BOOL)al_isExecutingPriorityConstraintsBlock -{ - return [[self al_globalConstraintPriorities] count] > 0; -} - -/** - Sets the constraint priority to the given value for all constraints created using the PureLayout - API within the given constraints block. - - NOTE: This method will have no effect (and will NOT set the priority) on constraints created or added - without using the PureLayout API! - - @param priority The layout priority to be set on all constraints created in the constraints block. - @param block A block of method calls to the PureLayout API that create and install constraints. - */ -+ (void)autoSetPriority:(ALLayoutPriority)priority forConstraints:(ALConstraintsBlock)block -{ - NSAssert(block, @"The constraints block cannot be nil."); - if (block) { - [[self al_globalConstraintPriorities] addObject:@(priority)]; - block(); - [[self al_globalConstraintPriorities] removeLastObject]; - } -} - - -#pragma mark Set Identifier For Constraints - -#if __PureLayout_MinBaseSDK_iOS_8_0 - -/** - A global variable that stores a stack of identifier strings to set on constraints. - When executing a constraints block passed into the +[autoSetIdentifier:forConstraints:] method, the identifier for - that call is pushed onto this stack, and when the block finishes executing, that identifier is popped off this - stack. If this stack contains at least 1 identifier, the identifier at the top of the stack will be set for all - constraints created by this library (even if automatic constraint installation is being prevented). - NOTE: Access to this variable is not synchronized (and should only be done on the main thread). - */ -static NSMutableArray *_al_globalConstraintIdentifiers = nil; - -/** - Accessor for the global state of constraint identifiers. - */ -+ (NSMutableArray *)al_globalConstraintIdentifiers -{ - if (!_al_globalConstraintIdentifiers) { - _al_globalConstraintIdentifiers = [NSMutableArray new]; - } - return _al_globalConstraintIdentifiers; -} - /** - Returns the current identifier string to use for constraints. - When executing a constraints block passed into +[autoSetIdentifier:forConstraints:], this will return - the identifier for the current block. Otherwise, nil is returned. - */ -+ (NSString *)al_currentGlobalConstraintIdentifier -{ - NSMutableArray *globalConstraintIdentifiers = [self al_globalConstraintIdentifiers]; - if ([globalConstraintIdentifiers count] == 0) { - return nil; - } - return [globalConstraintIdentifiers lastObject]; -} - -/** - Sets the identifier for all constraints created using the PureLayout API within the given constraints block. - - NOTE: This method will have no effect (and will NOT set the identifier) on constraints created or added - without using the PureLayout API! - - @param identifier A string used to identify all constraints created in the constraints block. - @param block A block of method calls to the PureLayout API that create and install constraints. + Configures an existing view to not convert the autoresizing mask into constraints and returns the view. */ -+ (void)autoSetIdentifier:(NSString *)identifier forConstraints:(ALConstraintsBlock)block +- (instancetype)configureForAutoLayout { - NSAssert(block, @"The constraints block cannot be nil."); - NSAssert(identifier, @"The identifier string cannot be nil."); - if (block) { - if (identifier) { - [[self al_globalConstraintIdentifiers] addObject:identifier]; - } - block(); - if (identifier) { - [[self al_globalConstraintIdentifiers] removeLastObject]; - } - } + self.translatesAutoresizingMaskIntoConstraints = NO; + return self; } -#endif /* __PureLayout_MinBaseSDK_iOS_8_0 */ - #pragma mark Center in Superview @@ -263,9 +78,9 @@ + (void)autoSetIdentifier:(NSString *)identifier forConstraints:(ALConstraintsBl @return An array of constraints added. */ -- (NSArray *)autoCenterInSuperview +- (__NSArray_of(NSLayoutConstraint *) *)autoCenterInSuperview { - NSMutableArray *constraints = [NSMutableArray new]; + __NSMutableArray_of(NSLayoutConstraint *) *constraints = [NSMutableArray new]; [constraints addObject:[self autoAlignAxisToSuperviewAxis:ALAxisHorizontal]]; [constraints addObject:[self autoAlignAxisToSuperviewAxis:ALAxisVertical]]; return constraints; @@ -292,9 +107,9 @@ - (NSLayoutConstraint *)autoAlignAxisToSuperviewAxis:(ALAxis)axis @return An array of constraints added. */ -- (NSArray *)autoCenterInSuperviewMargins +- (__NSArray_of(NSLayoutConstraint *) *)autoCenterInSuperviewMargins { - NSMutableArray *constraints = [NSMutableArray new]; + __NSMutableArray_of(NSLayoutConstraint *) *constraints = [NSMutableArray new]; [constraints addObject:[self autoAlignAxisToSuperviewMarginAxis:ALAxisHorizontal]]; [constraints addObject:[self autoAlignAxisToSuperviewMarginAxis:ALAxisVertical]]; return constraints; @@ -368,6 +183,16 @@ - (NSLayoutConstraint *)autoPinEdgeToSuperviewEdge:(ALEdge)edge withInset:(CGFlo return [self autoPinEdge:edge toEdge:edge ofView:superview withOffset:inset relation:relation]; } +/** + Pins the edges of the view to the edges of its superview. + + @return An array of constraints added. + */ +- (__NSArray_of(NSLayoutConstraint *) *)autoPinEdgesToSuperviewEdges +{ + return [self autoPinEdgesToSuperviewEdgesWithInsets:ALEdgeInsetsZero]; +} + /** Pins the edges of the view to the edges of its superview with the given edge insets. The insets.left corresponds to a leading edge constraint, and insets.right corresponds to a trailing edge constraint. @@ -375,9 +200,9 @@ - (NSLayoutConstraint *)autoPinEdgeToSuperviewEdge:(ALEdge)edge withInset:(CGFlo @param insets The insets for this view's edges from its superview's edges. @return An array of constraints added. */ -- (NSArray *)autoPinEdgesToSuperviewEdgesWithInsets:(ALEdgeInsets)insets +- (__NSArray_of(NSLayoutConstraint *) *)autoPinEdgesToSuperviewEdgesWithInsets:(ALEdgeInsets)insets { - NSMutableArray *constraints = [NSMutableArray new]; + __NSMutableArray_of(NSLayoutConstraint *) *constraints = [NSMutableArray new]; [constraints addObject:[self autoPinEdgeToSuperviewEdge:ALEdgeTop withInset:insets.top]]; [constraints addObject:[self autoPinEdgeToSuperviewEdge:ALEdgeLeading withInset:insets.left]]; [constraints addObject:[self autoPinEdgeToSuperviewEdge:ALEdgeBottom withInset:insets.bottom]]; @@ -394,9 +219,9 @@ - (NSArray *)autoPinEdgesToSuperviewEdgesWithInsets:(ALEdgeInsets)insets @param edge The edge of this view to exclude in pinning to its superview; this method will not apply any constraint to it. @return An array of constraints added. */ -- (NSArray *)autoPinEdgesToSuperviewEdgesWithInsets:(ALEdgeInsets)insets excludingEdge:(ALEdge)edge +- (__NSArray_of(NSLayoutConstraint *) *)autoPinEdgesToSuperviewEdgesWithInsets:(ALEdgeInsets)insets excludingEdge:(ALEdge)edge { - NSMutableArray *constraints = [NSMutableArray new]; + __NSMutableArray_of(NSLayoutConstraint *) *constraints = [NSMutableArray new]; if (edge != ALEdgeTop) { [constraints addObject:[self autoPinEdgeToSuperviewEdge:ALEdgeTop withInset:insets.top]]; } @@ -454,9 +279,9 @@ - (NSLayoutConstraint *)autoPinEdgeToSuperviewMargin:(ALEdge)edge relation:(NSLa @return An array of constraints added. */ -- (NSArray *)autoPinEdgesToSuperviewMargins +- (__NSArray_of(NSLayoutConstraint *) *)autoPinEdgesToSuperviewMargins { - NSMutableArray *constraints = [NSMutableArray new]; + __NSMutableArray_of(NSLayoutConstraint *) *constraints = [NSMutableArray new]; [constraints addObject:[self autoPinEdgeToSuperviewMargin:ALEdgeTop]]; [constraints addObject:[self autoPinEdgeToSuperviewMargin:ALEdgeLeading]]; [constraints addObject:[self autoPinEdgeToSuperviewMargin:ALEdgeBottom]]; @@ -470,9 +295,9 @@ - (NSArray *)autoPinEdgesToSuperviewMargins @param edge The edge of this view to exclude in pinning to its superview; this method will not apply any constraint to it. @return An array of constraints added. */ -- (NSArray *)autoPinEdgesToSuperviewMarginsExcludingEdge:(ALEdge)edge +- (__NSArray_of(NSLayoutConstraint *) *)autoPinEdgesToSuperviewMarginsExcludingEdge:(ALEdge)edge { - NSMutableArray *constraints = [NSMutableArray new]; + __NSMutableArray_of(NSLayoutConstraint *) *constraints = [NSMutableArray new]; if (edge != ALEdgeTop) { [constraints addObject:[self autoPinEdgeToSuperviewMargin:ALEdgeTop]]; } @@ -563,6 +388,19 @@ - (NSLayoutConstraint *)autoAlignAxis:(ALAxis)axis toSameAxisOfView:(ALView *)ot return [self autoConstrainAttribute:(ALAttribute)axis toAttribute:(ALAttribute)axis ofView:otherView withOffset:offset]; } +/** + Aligns an axis of the view to the same axis of another view with a multiplier. + + @param axis The axis of this view and the other view to align. + @param otherView The other view to align to. Must be in the same view hierarchy as this view. + @param multiplier The multiplier between the axis of this view and the axis of the other view. + @return The constraint added. + */ +- (NSLayoutConstraint *)autoAlignAxis:(ALAxis)axis toSameAxisOfView:(ALView *)otherView withMultiplier:(CGFloat)multiplier +{ + return [self autoConstrainAttribute:(ALAttribute)axis toAttribute:(ALAttribute)axis ofView:otherView withMultiplier:multiplier]; +} + #pragma mark Match Dimensions @@ -646,9 +484,9 @@ - (NSLayoutConstraint *)autoMatchDimension:(ALDimension)dimension toDimension:(A @param size The size to set this view's dimensions to. @return An array of constraints added. */ -- (NSArray *)autoSetDimensionsToSize:(CGSize)size +- (__NSArray_of(NSLayoutConstraint *) *)autoSetDimensionsToSize:(CGSize)size { - NSMutableArray *constraints = [NSMutableArray new]; + __NSMutableArray_of(NSLayoutConstraint *) *constraints = [NSMutableArray new]; [constraints addObject:[self autoSetDimension:ALDimensionWidth toSize:size.width]]; [constraints addObject:[self autoSetDimension:ALDimensionHeight toSize:size.height]]; return constraints; @@ -694,14 +532,14 @@ - (NSLayoutConstraint *)autoSetDimension:(ALDimension)dimension toSize:(CGFloat) */ - (void)autoSetContentCompressionResistancePriorityForAxis:(ALAxis)axis { - NSAssert([ALView al_isExecutingPriorityConstraintsBlock], @"%@ should only be called from within the block passed into the method +[autoSetPriority:forConstraints:]", NSStringFromSelector(_cmd)); - if ([ALView al_isExecutingPriorityConstraintsBlock]) { + NSAssert([NSLayoutConstraint al_isExecutingPriorityConstraintsBlock], @"%@ should only be called from within the block passed into the method +[autoSetPriority:forConstraints:]", NSStringFromSelector(_cmd)); + if ([NSLayoutConstraint al_isExecutingPriorityConstraintsBlock]) { self.translatesAutoresizingMaskIntoConstraints = NO; ALLayoutConstraintAxis constraintAxis = [NSLayoutConstraint al_constraintAxisForAxis:axis]; #if TARGET_OS_IPHONE - [self setContentCompressionResistancePriority:[ALView al_currentGlobalConstraintPriority] forAxis:constraintAxis]; + [self setContentCompressionResistancePriority:[NSLayoutConstraint al_currentGlobalConstraintPriority] forAxis:constraintAxis]; #else - [self setContentCompressionResistancePriority:[ALView al_currentGlobalConstraintPriority] forOrientation:constraintAxis]; + [self setContentCompressionResistancePriority:[NSLayoutConstraint al_currentGlobalConstraintPriority] forOrientation:constraintAxis]; #endif /* TARGET_OS_IPHONE */ } } @@ -714,14 +552,14 @@ - (void)autoSetContentCompressionResistancePriorityForAxis:(ALAxis)axis */ - (void)autoSetContentHuggingPriorityForAxis:(ALAxis)axis { - NSAssert([ALView al_isExecutingPriorityConstraintsBlock], @"%@ should only be called from within the block passed into the method +[autoSetPriority:forConstraints:]", NSStringFromSelector(_cmd)); - if ([ALView al_isExecutingPriorityConstraintsBlock]) { + NSAssert([NSLayoutConstraint al_isExecutingPriorityConstraintsBlock], @"%@ should only be called from within the block passed into the method +[autoSetPriority:forConstraints:]", NSStringFromSelector(_cmd)); + if ([NSLayoutConstraint al_isExecutingPriorityConstraintsBlock]) { self.translatesAutoresizingMaskIntoConstraints = NO; ALLayoutConstraintAxis constraintAxis = [NSLayoutConstraint al_constraintAxisForAxis:axis]; #if TARGET_OS_IPHONE - [self setContentHuggingPriority:[ALView al_currentGlobalConstraintPriority] forAxis:constraintAxis]; + [self setContentHuggingPriority:[NSLayoutConstraint al_currentGlobalConstraintPriority] forAxis:constraintAxis]; #else - [self setContentHuggingPriority:[ALView al_currentGlobalConstraintPriority] forOrientation:constraintAxis]; + [self setContentHuggingPriority:[NSLayoutConstraint al_currentGlobalConstraintPriority] forOrientation:constraintAxis]; #endif /* TARGET_OS_IPHONE */ } } @@ -884,100 +722,8 @@ - (NSLayoutConstraint *)autoPinToBottomLayoutGuideOfViewController:(UIViewContro #endif /* TARGET_OS_IPHONE */ -#pragma mark Deprecated Methods - -/** - DEPRECATED as of PureLayout v2.0.0. Retain a reference to and remove specific constraints instead, or recreate the view(s) entirely to remove all constraints. - Removes all explicit constraints that affect the view. - WARNING: Apple's constraint solver is not optimized for large-scale constraint removal; you may encounter major performance issues after using this method. - It is not recommended to use this method to "reset" a view for reuse in a different way with new constraints. Create a new view instead. - NOTE: This method preserves implicit constraints, such as intrinsic content size constraints, which you usually do not want to remove. - */ -- (void)autoRemoveConstraintsAffectingView -{ - [self autoRemoveConstraintsAffectingViewIncludingImplicitConstraints:NO]; -} - -/** - DEPRECATED as of PureLayout v2.0.0. Retain a reference to and remove specific constraints instead, or recreate the view(s) entirely to remove all constraints. - Removes all constraints that affect the view, optionally including implicit constraints. - WARNING: Apple's constraint solver is not optimized for large-scale constraint removal; you may encounter major performance issues after using this method. - It is not recommended to use this method to "reset" a view for reuse in a different way with new constraints. Create a new view instead. - NOTE: Implicit constraints are auto-generated lower priority constraints (such as those that attempt to keep a view at - its intrinsic content size by hugging its content & resisting compression), and you usually do not want to remove these. - - @param shouldRemoveImplicitConstraints Whether implicit constraints should be removed or skipped. - */ -- (void)autoRemoveConstraintsAffectingViewIncludingImplicitConstraints:(BOOL)shouldRemoveImplicitConstraints -{ - NSMutableArray *constraintsToRemove = [NSMutableArray new]; - ALView *startView = self; - do { - for (NSLayoutConstraint *constraint in startView.constraints) { - BOOL isImplicitConstraint = [NSStringFromClass([constraint class]) isEqualToString:@"NSContentSizeLayoutConstraint"]; - if (shouldRemoveImplicitConstraints || !isImplicitConstraint) { - if (constraint.firstItem == self || constraint.secondItem == self) { - [constraintsToRemove addObject:constraint]; - } - } - } - startView = startView.superview; - } while (startView); - [constraintsToRemove autoRemoveConstraints]; -} - -/** - DEPRECATED as of PureLayout v2.0.0. Retain a reference to and remove specific constraints instead, or recreate the view(s) entirely to remove all constraints. - Recursively removes all explicit constraints that affect the view and its subviews. - WARNING: Apple's constraint solver is not optimized for large-scale constraint removal; you may encounter major performance issues after using this method. - It is not recommended to use this method to "reset" views for reuse in a different way with new constraints. Create a new view instead. - NOTE: This method preserves implicit constraints, such as intrinsic content size constraints, which you usually do not want to remove. - */ -- (void)autoRemoveConstraintsAffectingViewAndSubviews -{ - [self autoRemoveConstraintsAffectingViewAndSubviewsIncludingImplicitConstraints:NO]; -} - -/** - DEPRECATED as of PureLayout v2.0.0. Retain a reference to and remove specific constraints instead, or recreate the view(s) entirely to remove all constraints. - Recursively removes all constraints that affect the view and its subviews, optionally including implicit constraints. - WARNING: Apple's constraint solver is not optimized for large-scale constraint removal; you may encounter major performance issues after using this method. - It is not recommended to use this method to "reset" views for reuse in a different way with new constraints. Create a new view instead. - NOTE: Implicit constraints are auto-generated lower priority constraints (such as those that attempt to keep a view at - its intrinsic content size by hugging its content & resisting compression), and you usually do not want to remove these. - - @param shouldRemoveImplicitConstraints Whether implicit constraints should be removed or skipped. - */ -- (void)autoRemoveConstraintsAffectingViewAndSubviewsIncludingImplicitConstraints:(BOOL)shouldRemoveImplicitConstraints -{ - [self autoRemoveConstraintsAffectingViewIncludingImplicitConstraints:shouldRemoveImplicitConstraints]; - for (ALView *subview in self.subviews) { - [subview autoRemoveConstraintsAffectingViewAndSubviewsIncludingImplicitConstraints:shouldRemoveImplicitConstraints]; - } -} - - #pragma mark Internal Methods -/** - Applies the global constraint priority and identifier to the given constraint. - This should be done before installing all constraints. - - @param constraint The constraint to set the global priority and identifier on. - */ -+ (void)al_applyGlobalStateToConstraint:(NSLayoutConstraint *)constraint -{ - if ([ALView al_isExecutingPriorityConstraintsBlock]) { - constraint.priority = [ALView al_currentGlobalConstraintPriority]; - } -#if __PureLayout_MinBaseSDK_iOS_8_0 - NSString *globalConstraintIdentifier = [ALView al_currentGlobalConstraintIdentifier]; - if (globalConstraintIdentifier) { - [constraint autoIdentify:globalConstraintIdentifier]; - } -#endif /* __PureLayout_MinBaseSDK_iOS_8_0 */ -} - /** Adds the given constraint to this view after applying the global state to the constraint. NOTE: This method is compatible with all versions of iOS, and should be used for older versions before the active @@ -989,9 +735,9 @@ + (void)al_applyGlobalStateToConstraint:(NSLayoutConstraint *)constraint */ - (void)al_addConstraint:(NSLayoutConstraint *)constraint { - [ALView al_applyGlobalStateToConstraint:constraint]; - if ([ALView al_preventAutomaticConstraintInstallation]) { - [[ALView al_currentArrayOfCreatedConstraints] addObject:constraint]; + [NSLayoutConstraint al_applyGlobalStateToConstraint:constraint]; + if ([NSLayoutConstraint al_preventAutomaticConstraintInstallation]) { + [[NSLayoutConstraint al_currentArrayOfCreatedConstraints] addObject:constraint]; } else { [self addConstraint:constraint]; } diff --git a/Pods/PureLayout/PureLayout/PureLayout/NSArray+PureLayout.h b/Pods/PureLayout/PureLayout/PureLayout/NSArray+PureLayout.h new file mode 100755 index 0000000..3815dc4 --- /dev/null +++ b/Pods/PureLayout/PureLayout/PureLayout/NSArray+PureLayout.h @@ -0,0 +1,115 @@ +// +// NSArray+PureLayout.h +// https://github.com/smileyborg/PureLayout +// +// Copyright (c) 2012 Richard Turton +// Copyright (c) 2013-2015 Tyler Fox +// +// This code is distributed under the terms and conditions of the MIT license. +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to +// deal in the Software without restriction, including without limitation the +// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or +// sell copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS +// IN THE SOFTWARE. +// + +#import "PureLayoutDefines.h" + + +__PL_ASSUME_NONNULL_BEGIN + +#pragma mark NSArray+PureLayout + +/** + A category on NSArray that provides a simple yet powerful interface to: + - Manage an array of Auto Layout constraints + - Apply constraints to an array of views + */ +@interface NSArray (PureLayout) + + +#pragma mark Array of Constraints + +/** Activates the constraints in this array. */ +- (void)autoInstallConstraints; + +/** Deactivates the constraints in this array. */ +- (void)autoRemoveConstraints; + +#if __PureLayout_MinBaseSDK_iOS_8_0 || __PureLayout_MinBaseSDK_OSX_10_10 + +/** Sets the string as the identifier for the constraints in this array. Available in iOS 7.0 and OS X 10.9 and later. */ +- (instancetype)autoIdentifyConstraints:(NSString *)identifier; + +#endif /* __PureLayout_MinBaseSDK_iOS_8_0 || __PureLayout_MinBaseSDK_OSX_10_10 */ + + +#pragma mark Array of Views + +/** Aligns views in this array to one another along a given edge. */ +- (__NSArray_of(NSLayoutConstraint *) *)autoAlignViewsToEdge:(ALEdge)edge; + +/** Aligns views in this array to one another along a given axis. */ +- (__NSArray_of(NSLayoutConstraint *) *)autoAlignViewsToAxis:(ALAxis)axis; + +/** Matches a given dimension of all the views in this array. */ +- (__NSArray_of(NSLayoutConstraint *) *)autoMatchViewsDimension:(ALDimension)dimension; + +/** Sets the given dimension of all the views in this array to a given size. */ +- (__NSArray_of(NSLayoutConstraint *) *)autoSetViewsDimension:(ALDimension)dimension toSize:(CGFloat)size; + +/** Sets all of the views in this array to a given size. */ +- (__NSArray_of(NSLayoutConstraint *) *)autoSetViewsDimensionsToSize:(CGSize)size; + + +/** Distributes the views in this array equally along the selected axis in their superview. + Views will be the same size (variable) in the dimension along the axis and will have spacing (fixed) between them. */ +- (__NSArray_of(NSLayoutConstraint *) *)autoDistributeViewsAlongAxis:(ALAxis)axis + alignedTo:(ALAttribute)alignment + withFixedSpacing:(CGFloat)spacing; + +/** Distributes the views in this array equally along the selected axis in their superview. + Views will be the same size (variable) in the dimension along the axis and will have spacing (fixed) between them, with optional insets from the first and last views to their superview. */ +- (__NSArray_of(NSLayoutConstraint *) *)autoDistributeViewsAlongAxis:(ALAxis)axis + alignedTo:(ALAttribute)alignment + withFixedSpacing:(CGFloat)spacing + insetSpacing:(BOOL)shouldSpaceInsets; + +/** Distributes the views in this array equally along the selected axis in their superview. + Views will have spacing (fixed) between them, with optional insets from the first and last views to their superview, and optionally constrained to the same size in the dimension along the axis. */ +- (__NSArray_of(NSLayoutConstraint *) *)autoDistributeViewsAlongAxis:(ALAxis)axis + alignedTo:(ALAttribute)alignment + withFixedSpacing:(CGFloat)spacing + insetSpacing:(BOOL)shouldSpaceInsets + matchedSizes:(BOOL)shouldMatchSizes; + + +/** Distributes the views in this array equally along the selected axis in their superview. + Views will be the same size (fixed) in the dimension along the axis and will have spacing (variable) between them. */ +- (__NSArray_of(NSLayoutConstraint *) *)autoDistributeViewsAlongAxis:(ALAxis)axis + alignedTo:(ALAttribute)alignment + withFixedSize:(CGFloat)size; + +/** Distributes the views in this array equally along the selected axis in their superview. + Views will be the same size (fixed) in the dimension along the axis and will have spacing (variable) between them, with optional insets from the first and last views to their superview. */ +- (__NSArray_of(NSLayoutConstraint *) *)autoDistributeViewsAlongAxis:(ALAxis)axis + alignedTo:(ALAttribute)alignment + withFixedSize:(CGFloat)size + insetSpacing:(BOOL)shouldSpaceInsets; + +@end + +__PL_ASSUME_NONNULL_END diff --git a/TableViewCellWithAutoLayout/PureLayout/NSArray+PureLayout.m b/Pods/PureLayout/PureLayout/PureLayout/NSArray+PureLayout.m similarity index 83% rename from TableViewCellWithAutoLayout/PureLayout/NSArray+PureLayout.m rename to Pods/PureLayout/PureLayout/PureLayout/NSArray+PureLayout.m index 81c0fb5..bea0789 100755 --- a/TableViewCellWithAutoLayout/PureLayout/NSArray+PureLayout.m +++ b/Pods/PureLayout/PureLayout/PureLayout/NSArray+PureLayout.m @@ -1,6 +1,5 @@ // // NSArray+PureLayout.m -// v2.0.5 // https://github.com/smileyborg/PureLayout // // Copyright (c) 2012 Richard Turton @@ -49,11 +48,11 @@ - (void)autoInstallConstraints if ([NSLayoutConstraint respondsToSelector:@selector(activateConstraints:)]) { for (id object in self) { if ([object isKindOfClass:[NSLayoutConstraint class]]) { - [ALView al_applyGlobalStateToConstraint:object]; + [NSLayoutConstraint al_applyGlobalStateToConstraint:object]; } } - if ([ALView al_preventAutomaticConstraintInstallation]) { - [[ALView al_currentArrayOfCreatedConstraints] addObjectsFromArray:self]; + if ([NSLayoutConstraint al_preventAutomaticConstraintInstallation]) { + [[NSLayoutConstraint al_currentArrayOfCreatedConstraints] addObjectsFromArray:self]; } else { [NSLayoutConstraint activateConstraints:self]; } @@ -87,7 +86,7 @@ - (void)autoRemoveConstraints } } -#if __PureLayout_MinBaseSDK_iOS_8_0 +#if __PureLayout_MinBaseSDK_iOS_8_0 || __PureLayout_MinBaseSDK_OSX_10_10 /** Sets the string as the identifier for the constraints in this array. Available in iOS 7.0 and OS X 10.9 and later. @@ -107,7 +106,7 @@ - (instancetype)autoIdentifyConstraints:(NSString *)identifier return self; } -#endif /* __PureLayout_MinBaseSDK_iOS_8_0 */ +#endif /* __PureLayout_MinBaseSDK_iOS_8_0 || __PureLayout_MinBaseSDK_OSX_10_10 */ #pragma mark Array of Views @@ -119,10 +118,10 @@ - (instancetype)autoIdentifyConstraints:(NSString *)identifier @param edge The edge to which the views will be aligned. @return An array of constraints added. */ -- (NSArray *)autoAlignViewsToEdge:(ALEdge)edge +- (__NSArray_of(NSLayoutConstraint *) *)autoAlignViewsToEdge:(ALEdge)edge { NSAssert([self al_containsMinimumNumberOfViews:2], @"This array must contain at least 2 views."); - NSMutableArray *constraints = [NSMutableArray new]; + __NSMutableArray_of(NSLayoutConstraint *) *constraints = [NSMutableArray new]; ALView *previousView = nil; for (id object in self) { if ([object isKindOfClass:[ALView class]]) { @@ -144,10 +143,10 @@ - (NSArray *)autoAlignViewsToEdge:(ALEdge)edge @param axis The axis to which the views will be aligned. @return An array of constraints added. */ -- (NSArray *)autoAlignViewsToAxis:(ALAxis)axis +- (__NSArray_of(NSLayoutConstraint *) *)autoAlignViewsToAxis:(ALAxis)axis { NSAssert([self al_containsMinimumNumberOfViews:2], @"This array must contain at least 2 views."); - NSMutableArray *constraints = [NSMutableArray new]; + __NSMutableArray_of(NSLayoutConstraint *) *constraints = [NSMutableArray new]; ALView *previousView = nil; for (id object in self) { if ([object isKindOfClass:[ALView class]]) { @@ -169,10 +168,10 @@ - (NSArray *)autoAlignViewsToAxis:(ALAxis)axis @param dimension The dimension to match for all of the views. @return An array of constraints added. */ -- (NSArray *)autoMatchViewsDimension:(ALDimension)dimension +- (__NSArray_of(NSLayoutConstraint *) *)autoMatchViewsDimension:(ALDimension)dimension { NSAssert([self al_containsMinimumNumberOfViews:2], @"This array must contain at least 2 views."); - NSMutableArray *constraints = [NSMutableArray new]; + __NSMutableArray_of(NSLayoutConstraint *) *constraints = [NSMutableArray new]; ALView *previousView = nil; for (id object in self) { if ([object isKindOfClass:[ALView class]]) { @@ -195,10 +194,10 @@ - (NSArray *)autoMatchViewsDimension:(ALDimension)dimension @param size The size to set the given dimension of each view to. @return An array of constraints added. */ -- (NSArray *)autoSetViewsDimension:(ALDimension)dimension toSize:(CGFloat)size +- (__NSArray_of(NSLayoutConstraint *) *)autoSetViewsDimension:(ALDimension)dimension toSize:(CGFloat)size { NSAssert([self al_containsMinimumNumberOfViews:1], @"This array must contain at least 1 view."); - NSMutableArray *constraints = [NSMutableArray new]; + __NSMutableArray_of(NSLayoutConstraint *) *constraints = [NSMutableArray new]; for (id object in self) { if ([object isKindOfClass:[ALView class]]) { ALView *view = (ALView *)object; @@ -216,9 +215,9 @@ - (NSArray *)autoSetViewsDimension:(ALDimension)dimension toSize:(CGFloat)size @param size The size to set each view's dimensions to. @return An array of constraints added. */ -- (NSArray *)autoSetViewsDimensionsToSize:(CGSize)size +- (__NSArray_of(NSLayoutConstraint *) *)autoSetViewsDimensionsToSize:(CGSize)size { - NSMutableArray *constraints = [NSMutableArray new]; + __NSMutableArray_of(NSLayoutConstraint *) *constraints = [NSMutableArray new]; [constraints addObjectsFromArray:[self autoSetViewsDimension:ALDimensionWidth toSize:size.width]]; [constraints addObjectsFromArray:[self autoSetViewsDimension:ALDimensionHeight toSize:size.height]]; return constraints; @@ -235,9 +234,9 @@ Views will be the same size (variable) in the dimension along the axis and will @param spacing The fixed amount of spacing between each view. @return An array of constraints added. */ -- (NSArray *)autoDistributeViewsAlongAxis:(ALAxis)axis - alignedTo:(ALAttribute)alignment - withFixedSpacing:(CGFloat)spacing +- (__NSArray_of(NSLayoutConstraint *) *)autoDistributeViewsAlongAxis:(ALAxis)axis + alignedTo:(ALAttribute)alignment + withFixedSpacing:(CGFloat)spacing { return [self autoDistributeViewsAlongAxis:axis alignedTo:alignment @@ -256,10 +255,10 @@ Views will be the same size (variable) in the dimension along the axis and will @param shouldSpaceInsets Whether the first and last views should be equally inset from their superview. @return An array of constraints added. */ -- (NSArray *)autoDistributeViewsAlongAxis:(ALAxis)axis - alignedTo:(ALAttribute)alignment - withFixedSpacing:(CGFloat)spacing - insetSpacing:(BOOL)shouldSpaceInsets +- (__NSArray_of(NSLayoutConstraint *) *)autoDistributeViewsAlongAxis:(ALAxis)axis + alignedTo:(ALAttribute)alignment + withFixedSpacing:(CGFloat)spacing + insetSpacing:(BOOL)shouldSpaceInsets { return [self autoDistributeViewsAlongAxis:axis alignedTo:alignment @@ -281,13 +280,13 @@ - (NSArray *)autoDistributeViewsAlongAxis:(ALAxis)axis NOTE: All views must specify an intrinsic content size if passing NO, otherwise the layout will be ambiguous! @return An array of constraints added. */ -- (NSArray *)autoDistributeViewsAlongAxis:(ALAxis)axis - alignedTo:(ALAttribute)alignment - withFixedSpacing:(CGFloat)spacing - insetSpacing:(BOOL)shouldSpaceInsets - matchedSizes:(BOOL)shouldMatchSizes +- (__NSArray_of(NSLayoutConstraint *) *)autoDistributeViewsAlongAxis:(ALAxis)axis + alignedTo:(ALAttribute)alignment + withFixedSpacing:(CGFloat)spacing + insetSpacing:(BOOL)shouldSpaceInsets + matchedSizes:(BOOL)shouldMatchSizes { - NSAssert([self al_containsMinimumNumberOfViews:2], @"This array must contain at least 2 views to distribute."); + NSAssert([self al_containsMinimumNumberOfViews:1], @"This array must contain at least 1 view to distribute."); ALDimension matchedDimension; ALEdge firstEdge, lastEdge; switch (axis) { @@ -312,7 +311,7 @@ - (NSArray *)autoDistributeViewsAlongAxis:(ALAxis)axis CGFloat leadingSpacing = shouldSpaceInsets ? spacing : 0.0; CGFloat trailingSpacing = shouldSpaceInsets ? spacing : 0.0; - NSMutableArray *constraints = [NSMutableArray new]; + __NSMutableArray_of(NSLayoutConstraint *) *constraints = [NSMutableArray new]; ALView *previousView = nil; for (id object in self) { if ([object isKindOfClass:[ALView class]]) { @@ -350,9 +349,9 @@ Views will be the same size (fixed) in the dimension along the axis and will hav @param size The fixed size of each view in the dimension along the given axis. @return An array of constraints added. */ -- (NSArray *)autoDistributeViewsAlongAxis:(ALAxis)axis - alignedTo:(ALAttribute)alignment - withFixedSize:(CGFloat)size +- (__NSArray_of(NSLayoutConstraint *) *)autoDistributeViewsAlongAxis:(ALAxis)axis + alignedTo:(ALAttribute)alignment + withFixedSize:(CGFloat)size { return [self autoDistributeViewsAlongAxis:axis alignedTo:alignment @@ -371,12 +370,12 @@ Views will be the same size (fixed) in the dimension along the axis and will hav @param shouldSpaceInsets Whether the first and last views should be equally inset from their superview. @return An array of constraints added. */ -- (NSArray *)autoDistributeViewsAlongAxis:(ALAxis)axis - alignedTo:(ALAttribute)alignment - withFixedSize:(CGFloat)size - insetSpacing:(BOOL)shouldSpaceInsets +- (__NSArray_of(NSLayoutConstraint *) *)autoDistributeViewsAlongAxis:(ALAxis)axis + alignedTo:(ALAttribute)alignment + withFixedSize:(CGFloat)size + insetSpacing:(BOOL)shouldSpaceInsets { - NSAssert([self al_containsMinimumNumberOfViews:2], @"This array must contain at least 2 views to distribute."); + NSAssert([self al_containsMinimumNumberOfViews:1], @"This array must contain at least 1 view to distribute."); ALDimension fixedDimension; NSLayoutAttribute attribute; switch (axis) { @@ -408,8 +407,8 @@ - (NSArray *)autoDistributeViewsAlongAxis:(ALAxis)axis #endif /* TARGET_OS_IPHONE */ BOOL shouldFlipOrder = isRightToLeftLayout && (axis != ALAxisVertical); // imitate the effect of leading/trailing when distributing horizontally - NSMutableArray *constraints = [NSMutableArray new]; - NSArray *views = [self al_copyViewsOnly]; + __NSMutableArray_of(NSLayoutConstraint *) *constraints = [NSMutableArray new]; + __NSArray_of(ALView *) *views = [self al_copyViewsOnly]; NSUInteger numberOfViews = [views count]; ALView *commonSuperview = [views al_commonSuperviewOfViews]; ALView *previousView = nil; @@ -443,7 +442,7 @@ - (NSArray *)autoDistributeViewsAlongAxis:(ALAxis)axis #pragma mark Internal Helper Methods /** - Returns the common superview for the views in this array. + Returns the common superview for the views in this array. If there is only one view in the array, its superview will be returned. Raises an exception if the views in this array do not share a common superview. @return The common superview for the views in this array. @@ -458,7 +457,7 @@ - (ALView *)al_commonSuperviewOfViews if (previousView) { commonSuperview = [view al_commonSuperviewWithView:commonSuperview]; } else { - commonSuperview = view; + commonSuperview = view.superview; } previousView = view; } @@ -492,9 +491,9 @@ - (BOOL)al_containsMinimumNumberOfViews:(NSUInteger)minimumNumberOfViews @return A new array containing only the views that are in this array. */ -- (NSArray *)al_copyViewsOnly +- (__NSArray_of(ALView *) *)al_copyViewsOnly { - NSMutableArray *viewsOnlyArray = [NSMutableArray arrayWithCapacity:[self count]]; + __NSMutableArray_of(ALView *) *viewsOnlyArray = [NSMutableArray arrayWithCapacity:[self count]]; for (id object in self) { if ([object isKindOfClass:[ALView class]]) { [viewsOnlyArray addObject:object]; diff --git a/TableViewCellWithAutoLayout/PureLayout/NSLayoutConstraint+PureLayout.h b/Pods/PureLayout/PureLayout/PureLayout/NSLayoutConstraint+PureLayout.h similarity index 55% rename from TableViewCellWithAutoLayout/PureLayout/NSLayoutConstraint+PureLayout.h rename to Pods/PureLayout/PureLayout/PureLayout/NSLayoutConstraint+PureLayout.h index 87797f6..01a1dc6 100755 --- a/TableViewCellWithAutoLayout/PureLayout/NSLayoutConstraint+PureLayout.h +++ b/Pods/PureLayout/PureLayout/PureLayout/NSLayoutConstraint+PureLayout.h @@ -1,6 +1,5 @@ // // NSLayoutConstraint+PureLayout.h -// v2.0.5 // https://github.com/smileyborg/PureLayout // // Copyright (c) 2013-2015 Tyler Fox @@ -29,7 +28,9 @@ #import "PureLayoutDefines.h" -#pragma mark - NSLayoutConstraint+PureLayout +__PL_ASSUME_NONNULL_BEGIN + +#pragma mark NSLayoutConstraint+PureLayout /** A category on NSLayoutConstraint that allows constraints to be easily installed & removed. @@ -37,22 +38,47 @@ @interface NSLayoutConstraint (PureLayout) -#pragma mark Install & Remove Constraints +#pragma mark Batch Constraint Creation -/** Activates the the constraint. */ -- (void)autoInstall; +/** Creates all of the constraints in the block, then installs (activates) them all at once. + All constraints created from calls to the PureLayout API in the block are returned in a single array. + This may be more efficient than installing (activating) each constraint one-by-one. */ ++ (__NSArray_of(NSLayoutConstraint *) *)autoCreateAndInstallConstraints:(ALConstraintsBlock)block; -/** Deactivates the constraint. */ -- (void)autoRemove; +/** Creates all of the constraints in the block but prevents them from being automatically installed (activated). + All constraints created from calls to the PureLayout API in the block are returned in a single array. */ ++ (__NSArray_of(NSLayoutConstraint *) *)autoCreateConstraintsWithoutInstalling:(ALConstraintsBlock)block; + + +#pragma mark Set Priority For Constraints + +/** Sets the constraint priority to the given value for all constraints created using the PureLayout API within the given constraints block. + NOTE: This method will have no effect (and will NOT set the priority) on constraints created or added without using the PureLayout API! */ ++ (void)autoSetPriority:(ALLayoutPriority)priority forConstraints:(ALConstraintsBlock)block; #pragma mark Identify Constraints #if __PureLayout_MinBaseSDK_iOS_8_0 || __PureLayout_MinBaseSDK_OSX_10_10 +/** Sets the identifier for all constraints created using the PureLayout API within the given constraints block. + NOTE: This method will have no effect (and will NOT set the identifier) on constraints created or added without using the PureLayout API! */ ++ (void)autoSetIdentifier:(NSString *)identifier forConstraints:(ALConstraintsBlock)block; + /** Sets the string as the identifier for this constraint. Available in iOS 7.0 and OS X 10.9 and later. */ - (instancetype)autoIdentify:(NSString *)identifier; #endif /* __PureLayout_MinBaseSDK_iOS_8_0 || __PureLayout_MinBaseSDK_OSX_10_10 */ + +#pragma mark Install & Remove Constraints + +/** Activates the the constraint. */ +- (void)autoInstall; + +/** Deactivates the constraint. */ +- (void)autoRemove; + @end + +__PL_ASSUME_NONNULL_END diff --git a/Pods/PureLayout/PureLayout/PureLayout/NSLayoutConstraint+PureLayout.m b/Pods/PureLayout/PureLayout/PureLayout/NSLayoutConstraint+PureLayout.m new file mode 100755 index 0000000..6c3cef2 --- /dev/null +++ b/Pods/PureLayout/PureLayout/PureLayout/NSLayoutConstraint+PureLayout.m @@ -0,0 +1,552 @@ +// +// NSLayoutConstraint+PureLayout.m +// https://github.com/smileyborg/PureLayout +// +// Copyright (c) 2013-2015 Tyler Fox +// +// This code is distributed under the terms and conditions of the MIT license. +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to +// deal in the Software without restriction, including without limitation the +// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or +// sell copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS +// IN THE SOFTWARE. +// + +#import "NSLayoutConstraint+PureLayout.h" +#import "ALView+PureLayout.h" +#import "NSArray+PureLayout.h" +#import "PureLayout+Internal.h" + + +#pragma mark - NSLayoutConstraint+PureLayout + +@implementation NSLayoutConstraint (PureLayout) + +#pragma mark Batch Constraint Creation + +/** + A global variable that stores a stack of arrays of constraints created without being immediately installed. + When executing a constraints block passed into the +[autoCreateConstraintsWithoutInstalling:] method, a new + mutable array is pushed onto this stack, and all constraints created with PureLayout in the block are added + to this array. When the block finishes executing, the array is popped off this stack. Automatic constraint + installation is prevented if this stack contains at least 1 array. + + NOTE: Access to this variable is not synchronized (and should only be done on the main thread). + */ +static __NSMutableArray_of(__NSMutableArray_of(NSLayoutConstraint *) *) *_al_arraysOfCreatedConstraints = nil; + +/** + A global variable that is set to YES when installing a batch of constraints collected from a call to +[autoCreateAndInstallConstraints]. + When this flag is YES, constraints are installed immediately without checking for or adding to the +[al_currentArrayOfCreatedConstraints]. + This is necessary to properly handle nested calls to +[autoCreateAndInstallConstraints], where calls whose block contains other call(s) + should not return constraints from within the blocks of nested call(s). + */ +static BOOL _al_isInstallingCreatedConstraints = NO; + +/** + Accessor for the global state that stores arrays of constraints created without being installed. + */ ++ (__NSMutableArray_of(__NSMutableArray_of(NSLayoutConstraint *) *) *)al_arraysOfCreatedConstraints +{ + NSAssert([NSThread isMainThread], @"PureLayout is not thread safe, and must be used exclusively from the main thread."); + if (!_al_arraysOfCreatedConstraints) { + _al_arraysOfCreatedConstraints = [NSMutableArray new]; + } + return _al_arraysOfCreatedConstraints; +} + +/** + Accessor for the current mutable array of constraints created without being immediately installed. + */ ++ (__NSMutableArray_of(NSLayoutConstraint *) *)al_currentArrayOfCreatedConstraints +{ + return [[self al_arraysOfCreatedConstraints] lastObject]; +} + +/** + Accessor for the global state that determines whether automatic constraint installation should be prevented. + */ ++ (BOOL)al_preventAutomaticConstraintInstallation +{ + return (_al_isInstallingCreatedConstraints == NO) && ([[self al_arraysOfCreatedConstraints] count] > 0); +} + +/** + Creates all of the constraints in the block, then installs (activates) them all at once. + All constraints created from calls to the PureLayout API in the block are returned in a single array. + This may be more efficient than installing (activating) each constraint one-by-one. + + Note: calls to this method may be nested. The constraints returned from a call will NOT include constraints + created in nested calls; constraints are only returned from the inner-most call they are created within. + + @param block A block of method calls to the PureLayout API that create constraints. + @return An array of the constraints that were created from calls to the PureLayout API inside the block. + */ ++ (__NSArray_of(NSLayoutConstraint *) *)autoCreateAndInstallConstraints:(ALConstraintsBlock)block +{ + NSArray *createdConstraints = [self autoCreateConstraintsWithoutInstalling:block]; + _al_isInstallingCreatedConstraints = YES; + [createdConstraints autoInstallConstraints]; + _al_isInstallingCreatedConstraints = NO; + return createdConstraints; +} + +/** + Creates all of the constraints in the block but prevents them from being automatically installed (activated). + All constraints created from calls to the PureLayout API in the block are returned in a single array. + + Note: calls to this method may be nested. The constraints returned from a call will NOT include constraints + created in nested calls; constraints are only returned from the inner-most call they are created within. + + @param block A block of method calls to the PureLayout API that create constraints. + @return An array of the constraints that were created from calls to the PureLayout API inside the block. + */ ++ (__NSArray_of(NSLayoutConstraint *) *)autoCreateConstraintsWithoutInstalling:(ALConstraintsBlock)block +{ + NSAssert(block, @"The constraints block cannot be nil."); + NSArray *createdConstraints = nil; + if (block) { + [[self al_arraysOfCreatedConstraints] addObject:[NSMutableArray new]]; + block(); + createdConstraints = [self al_currentArrayOfCreatedConstraints]; + [[self al_arraysOfCreatedConstraints] removeLastObject]; + } + return createdConstraints; +} + + +#pragma mark Set Priority For Constraints + +/** + A global variable that stores a stack of layout priorities to set on constraints. + When executing a constraints block passed into the +[autoSetPriority:forConstraints:] method, the priority for + that call is pushed onto this stack, and when the block finishes executing, that priority is popped off this + stack. If this stack contains at least 1 priority, the priority at the top of the stack will be set for all + constraints created by this library (even if automatic constraint installation is being prevented). + NOTE: Access to this variable is not synchronized (and should only be done on the main thread). + */ +static __NSMutableArray_of(NSNumber *) *_al_globalConstraintPriorities = nil; + +/** + Accessor for the global stack of layout priorities. + */ ++ (__NSMutableArray_of(NSNumber *) *)al_globalConstraintPriorities +{ + NSAssert([NSThread isMainThread], @"PureLayout is not thread safe, and must be used exclusively from the main thread."); + if (!_al_globalConstraintPriorities) { + _al_globalConstraintPriorities = [NSMutableArray new]; + } + return _al_globalConstraintPriorities; +} + +/** + Returns the current layout priority to use for constraints. + When executing a constraints block passed into +[autoSetPriority:forConstraints:], this will return + the priority for the current block. Otherwise, the default Required priority is returned. + */ ++ (ALLayoutPriority)al_currentGlobalConstraintPriority +{ + __NSMutableArray_of(NSNumber *) *globalConstraintPriorities = [self al_globalConstraintPriorities]; + if ([globalConstraintPriorities count] == 0) { + return ALLayoutPriorityRequired; + } + return [[globalConstraintPriorities lastObject] floatValue]; +} + +/** + Accessor for the global state that determines if we're currently in the scope of a priority constraints block. + */ ++ (BOOL)al_isExecutingPriorityConstraintsBlock +{ + return [[self al_globalConstraintPriorities] count] > 0; +} + +/** + Sets the constraint priority to the given value for all constraints created using the PureLayout + API within the given constraints block. + + NOTE: This method will have no effect (and will NOT set the priority) on constraints created or added + without using the PureLayout API! + + @param priority The layout priority to be set on all constraints created in the constraints block. + @param block A block of method calls to the PureLayout API that create and install constraints. + */ ++ (void)autoSetPriority:(ALLayoutPriority)priority forConstraints:(ALConstraintsBlock)block +{ + NSAssert(block, @"The constraints block cannot be nil."); + if (block) { + [[self al_globalConstraintPriorities] addObject:@(priority)]; + block(); + [[self al_globalConstraintPriorities] removeLastObject]; + } +} + + +#pragma mark Identify Constraints + +#if __PureLayout_MinBaseSDK_iOS_8_0 || __PureLayout_MinBaseSDK_OSX_10_10 + +/** + A global variable that stores a stack of identifier strings to set on constraints. + When executing a constraints block passed into the +[autoSetIdentifier:forConstraints:] method, the identifier for + that call is pushed onto this stack, and when the block finishes executing, that identifier is popped off this + stack. If this stack contains at least 1 identifier, the identifier at the top of the stack will be set for all + constraints created by this library (even if automatic constraint installation is being prevented). + NOTE: Access to this variable is not synchronized (and should only be done on the main thread). + */ +static __NSMutableArray_of(NSString *) *_al_globalConstraintIdentifiers = nil; + +/** + Accessor for the global state of constraint identifiers. + */ ++ (__NSMutableArray_of(NSString *) *)al_globalConstraintIdentifiers +{ + NSAssert([NSThread isMainThread], @"PureLayout is not thread safe, and must be used exclusively from the main thread."); + if (!_al_globalConstraintIdentifiers) { + _al_globalConstraintIdentifiers = [NSMutableArray new]; + } + return _al_globalConstraintIdentifiers; +} + +/** + Returns the current identifier string to use for constraints. + When executing a constraints block passed into +[autoSetIdentifier:forConstraints:], this will return + the identifier for the current block. Otherwise, nil is returned. + */ ++ (NSString *)al_currentGlobalConstraintIdentifier +{ + __NSMutableArray_of(NSString *) *globalConstraintIdentifiers = [self al_globalConstraintIdentifiers]; + if ([globalConstraintIdentifiers count] == 0) { + return nil; + } + return [globalConstraintIdentifiers lastObject]; +} + +/** + Sets the identifier for all constraints created using the PureLayout API within the given constraints block. + + NOTE: This method will have no effect (and will NOT set the identifier) on constraints created or added + without using the PureLayout API! + + @param identifier A string used to identify all constraints created in the constraints block. + @param block A block of method calls to the PureLayout API that create and install constraints. + */ ++ (void)autoSetIdentifier:(NSString *)identifier forConstraints:(ALConstraintsBlock)block +{ + NSAssert(block, @"The constraints block cannot be nil."); + NSAssert(identifier, @"The identifier string cannot be nil."); + if (block) { + if (identifier) { + [[self al_globalConstraintIdentifiers] addObject:identifier]; + } + block(); + if (identifier) { + [[self al_globalConstraintIdentifiers] removeLastObject]; + } + } +} + +/** + Sets the string as the identifier for this constraint. Available in iOS 7.0 and OS X 10.9 and later. + The identifier will be printed along with the constraint's description. + This is helpful to document a constraint's purpose and aid in debugging. + + @param identifier A string used to identify this constraint. + @return This constraint. + */ +- (instancetype)autoIdentify:(NSString *)identifier +{ + if ([self respondsToSelector:@selector(setIdentifier:)]) { + self.identifier = identifier; + } + return self; +} + +#endif /* __PureLayout_MinBaseSDK_iOS_8_0 || __PureLayout_MinBaseSDK_OSX_10_10 */ + + +#pragma mark Install & Remove Constraints + +/** + Activates the constraint. + */ +- (void)autoInstall +{ +#if __PureLayout_MinBaseSDK_iOS_8_0 || __PureLayout_MinBaseSDK_OSX_10_10 + if ([self respondsToSelector:@selector(setActive:)]) { + [NSLayoutConstraint al_applyGlobalStateToConstraint:self]; + if ([NSLayoutConstraint al_preventAutomaticConstraintInstallation]) { + [[NSLayoutConstraint al_currentArrayOfCreatedConstraints] addObject:self]; + } else { + self.active = YES; + } + return; + } +#endif /* __PureLayout_MinBaseSDK_iOS_8_0 || __PureLayout_MinBaseSDK_OSX_10_10 */ + + NSAssert(self.firstItem || self.secondItem, @"Can't install a constraint with nil firstItem and secondItem."); + if (self.firstItem) { + if (self.secondItem) { + NSAssert([self.firstItem isKindOfClass:[ALView class]] && [self.secondItem isKindOfClass:[ALView class]], @"Can only automatically install a constraint if both items are views."); + ALView *commonSuperview = [self.firstItem al_commonSuperviewWithView:self.secondItem]; + [commonSuperview al_addConstraint:self]; + } else { + NSAssert([self.firstItem isKindOfClass:[ALView class]], @"Can only automatically install a constraint if the item is a view."); + [self.firstItem al_addConstraint:self]; + } + } else { + NSAssert([self.secondItem isKindOfClass:[ALView class]], @"Can only automatically install a constraint if the item is a view."); + [self.secondItem al_addConstraint:self]; + } +} + +/** + Deactivates the constraint. + */ +- (void)autoRemove +{ +#if __PureLayout_MinBaseSDK_iOS_8_0 || __PureLayout_MinBaseSDK_OSX_10_10 + if ([self respondsToSelector:@selector(setActive:)]) { + self.active = NO; + return; + } +#endif /* __PureLayout_MinBaseSDK_iOS_8_0 || __PureLayout_MinBaseSDK_OSX_10_10 */ + + if (self.secondItem) { + ALView *commonSuperview = [self.firstItem al_commonSuperviewWithView:self.secondItem]; + while (commonSuperview) { + if ([commonSuperview.constraints containsObject:self]) { + [commonSuperview removeConstraint:self]; + return; + } + commonSuperview = commonSuperview.superview; + } + } + else { + [self.firstItem removeConstraint:self]; + return; + } + NSAssert(nil, @"Failed to remove constraint: %@", self); +} + + +#pragma mark Internal Methods + +/** + Applies the global constraint priority and identifier to the given constraint. + This should be done before installing all constraints. + + @param constraint The constraint to set the global priority and identifier on. + */ ++ (void)al_applyGlobalStateToConstraint:(NSLayoutConstraint *)constraint +{ + if ([NSLayoutConstraint al_isExecutingPriorityConstraintsBlock]) { + constraint.priority = [NSLayoutConstraint al_currentGlobalConstraintPriority]; + } +#if __PureLayout_MinBaseSDK_iOS_8_0 || __PureLayout_MinBaseSDK_OSX_10_10 + NSString *globalConstraintIdentifier = [NSLayoutConstraint al_currentGlobalConstraintIdentifier]; + if (globalConstraintIdentifier) { + [constraint autoIdentify:globalConstraintIdentifier]; + } +#endif /* __PureLayout_MinBaseSDK_iOS_8_0 || __PureLayout_MinBaseSDK_OSX_10_10 */ +} + +/** + Returns the corresponding NSLayoutAttribute for the given ALAttribute. + + @return The layout attribute for the given ALAttribute. + */ ++ (NSLayoutAttribute)al_layoutAttributeForAttribute:(ALAttribute)attribute +{ + NSLayoutAttribute layoutAttribute = NSLayoutAttributeNotAnAttribute; + switch (attribute) { + case ALEdgeLeft: + layoutAttribute = NSLayoutAttributeLeft; + break; + case ALEdgeRight: + layoutAttribute = NSLayoutAttributeRight; + break; + case ALEdgeTop: + layoutAttribute = NSLayoutAttributeTop; + break; + case ALEdgeBottom: + layoutAttribute = NSLayoutAttributeBottom; + break; + case ALEdgeLeading: + layoutAttribute = NSLayoutAttributeLeading; + break; + case ALEdgeTrailing: + layoutAttribute = NSLayoutAttributeTrailing; + break; + case ALDimensionWidth: + layoutAttribute = NSLayoutAttributeWidth; + break; + case ALDimensionHeight: + layoutAttribute = NSLayoutAttributeHeight; + break; + case ALAxisVertical: + layoutAttribute = NSLayoutAttributeCenterX; + break; + case ALAxisHorizontal: + layoutAttribute = NSLayoutAttributeCenterY; + break; + case ALAxisBaseline: // same value as ALAxisLastBaseline + layoutAttribute = NSLayoutAttributeBaseline; + break; +#if __PureLayout_MinBaseSDK_iOS_8_0 + case ALAxisFirstBaseline: + NSAssert(__PureLayout_MinSysVer_iOS_8_0, @"ALAxisFirstBaseline is only supported on iOS 8.0 or higher."); + layoutAttribute = NSLayoutAttributeFirstBaseline; + break; + case ALMarginLeft: + NSAssert(__PureLayout_MinSysVer_iOS_8_0, @"ALEdgeLeftMargin is only supported on iOS 8.0 or higher."); + layoutAttribute = NSLayoutAttributeLeftMargin; + break; + case ALMarginRight: + NSAssert(__PureLayout_MinSysVer_iOS_8_0, @"ALEdgeRightMargin is only supported on iOS 8.0 or higher."); + layoutAttribute = NSLayoutAttributeRightMargin; + break; + case ALMarginTop: + NSAssert(__PureLayout_MinSysVer_iOS_8_0, @"ALEdgeTopMargin is only supported on iOS 8.0 or higher."); + layoutAttribute = NSLayoutAttributeTopMargin; + break; + case ALMarginBottom: + NSAssert(__PureLayout_MinSysVer_iOS_8_0, @"ALEdgeBottomMargin is only supported on iOS 8.0 or higher."); + layoutAttribute = NSLayoutAttributeBottomMargin; + break; + case ALMarginLeading: + NSAssert(__PureLayout_MinSysVer_iOS_8_0, @"ALEdgeLeadingMargin is only supported on iOS 8.0 or higher."); + layoutAttribute = NSLayoutAttributeLeadingMargin; + break; + case ALMarginTrailing: + NSAssert(__PureLayout_MinSysVer_iOS_8_0, @"ALEdgeTrailingMargin is only supported on iOS 8.0 or higher."); + layoutAttribute = NSLayoutAttributeTrailingMargin; + break; + case ALMarginAxisVertical: + NSAssert(__PureLayout_MinSysVer_iOS_8_0, @"ALAxisVerticalMargin is only supported on iOS 8.0 or higher."); + layoutAttribute = NSLayoutAttributeCenterXWithinMargins; + break; + case ALMarginAxisHorizontal: + NSAssert(__PureLayout_MinSysVer_iOS_8_0, @"ALAxisHorizontalMargin is only supported on iOS 8.0 or higher."); + layoutAttribute = NSLayoutAttributeCenterYWithinMargins; + break; +#endif /* __PureLayout_MinBaseSDK_iOS_8_0 */ + default: + NSAssert(nil, @"Not a valid ALAttribute."); + break; + } + return layoutAttribute; +} + +/** + Returns the corresponding ALLayoutConstraintAxis for the given ALAxis. + + @return The constraint axis for the given axis. + */ ++ (ALLayoutConstraintAxis)al_constraintAxisForAxis:(ALAxis)axis +{ + ALLayoutConstraintAxis constraintAxis; + switch (axis) { + case ALAxisVertical: + constraintAxis = ALLayoutConstraintAxisVertical; + break; + case ALAxisHorizontal: + case ALAxisBaseline: // same value as ALAxisLastBaseline +#if __PureLayout_MinBaseSDK_iOS_8_0 + case ALAxisFirstBaseline: +#endif /* __PureLayout_MinBaseSDK_iOS_8_0 */ + constraintAxis = ALLayoutConstraintAxisHorizontal; + break; + default: + NSAssert(nil, @"Not a valid ALAxis."); + constraintAxis = ALLayoutConstraintAxisHorizontal; // default to an arbitrary value to satisfy the compiler + break; + } + return constraintAxis; +} + +#if __PureLayout_MinBaseSDK_iOS_8_0 + +/** + Returns the corresponding margin for the given edge. + + @param edge The edge to convert to the corresponding margin. + @return The margin for the given edge. + */ ++ (ALMargin)al_marginForEdge:(ALEdge)edge +{ + NSAssert(__PureLayout_MinSysVer_iOS_8_0, @"Margin attributes are only supported on iOS 8.0 or higher."); + ALMargin margin; + switch (edge) { + case ALEdgeLeft: + margin = ALMarginLeft; + break; + case ALEdgeRight: + margin = ALMarginRight; + break; + case ALEdgeTop: + margin = ALMarginTop; + break; + case ALEdgeBottom: + margin = ALMarginBottom; + break; + case ALEdgeLeading: + margin = ALMarginLeading; + break; + case ALEdgeTrailing: + margin = ALMarginTrailing; + break; + default: + NSAssert(nil, @"Not a valid ALEdge."); + margin = ALMarginLeft; // default to an arbitrary value to satisfy the compiler + break; + } + return margin; +} + +/** + Returns the corresponding margin axis for the given axis. + + @param axis The axis to convert to the corresponding margin axis. + @return The margin axis for the given axis. + */ ++ (ALMarginAxis)al_marginAxisForAxis:(ALAxis)axis +{ + NSAssert(__PureLayout_MinSysVer_iOS_8_0, @"Margin attributes are only supported on iOS 8.0 or higher."); + ALMarginAxis marginAxis; + switch (axis) { + case ALAxisVertical: + marginAxis = ALMarginAxisVertical; + break; + case ALAxisHorizontal: + marginAxis = ALMarginAxisHorizontal; + break; + case ALAxisBaseline: + case ALAxisFirstBaseline: + NSAssert(nil, @"The baseline axis attributes do not have corresponding margin axis attributes."); + marginAxis = ALMarginAxisVertical; // default to an arbitrary value to satisfy the compiler + break; + default: + NSAssert(nil, @"Not a valid ALAxis."); + marginAxis = ALMarginAxisVertical; // default to an arbitrary value to satisfy the compiler + break; + } + return marginAxis; +} + +#endif /* __PureLayout_MinBaseSDK_iOS_8_0 */ + +@end diff --git a/TableViewCellWithAutoLayout/PureLayout/PureLayout+Internal.h b/Pods/PureLayout/PureLayout/PureLayout/PureLayout+Internal.h similarity index 80% rename from TableViewCellWithAutoLayout/PureLayout/PureLayout+Internal.h rename to Pods/PureLayout/PureLayout/PureLayout/PureLayout+Internal.h index 28fbfcf..48335d4 100644 --- a/TableViewCellWithAutoLayout/PureLayout/PureLayout+Internal.h +++ b/Pods/PureLayout/PureLayout/PureLayout/PureLayout+Internal.h @@ -1,6 +1,5 @@ // // PureLayout+Internal.h -// v2.0.5 // https://github.com/smileyborg/PureLayout // // Copyright (c) 2014-2015 Tyler Fox @@ -28,9 +27,15 @@ #import "PureLayoutDefines.h" + +// Using generics with NSMutableArray is so common in the internal implementation of PureLayout that it gets a dedicated preprocessor macro for better readability. +#define __NSMutableArray_of(type) __PL_GENERICS(NSMutableArray, type) + +__PL_ASSUME_NONNULL_BEGIN + /** A constant that represents the smallest valid positive value for the multiplier of a constraint, since a value of 0 will cause the second item to be lost in the internal auto layout engine. */ -static const CGFloat kMULTIPLIER_MIN_VALUE = 0.00001; // very small floating point numbers (e.g. CGFLOAT_MIN) can cause problems +static const CGFloat kMULTIPLIER_MIN_VALUE = (CGFloat)0.00001; // very small floating point numbers (e.g. CGFLOAT_MIN) can cause problems /** @@ -38,12 +43,6 @@ static const CGFloat kMULTIPLIER_MIN_VALUE = 0.00001; // very small floating poi */ @interface ALView (PureLayoutInternal) -+ (BOOL)al_preventAutomaticConstraintInstallation; -+ (NSMutableArray *)al_currentArrayOfCreatedConstraints; -+ (BOOL)al_isExecutingPriorityConstraintsBlock; -+ (ALLayoutPriority)al_currentGlobalConstraintPriority; -+ (NSString *)al_currentGlobalConstraintIdentifier; -+ (void)al_applyGlobalStateToConstraint:(NSLayoutConstraint *)constraint; - (void)al_addConstraint:(NSLayoutConstraint *)constraint; - (ALView *)al_commonSuperviewWithView:(ALView *)otherView; - (NSLayoutConstraint *)al_alignAttribute:(ALAttribute)attribute toView:(ALView *)otherView forAxis:(ALAxis)axis; @@ -58,7 +57,7 @@ static const CGFloat kMULTIPLIER_MIN_VALUE = 0.00001; // very small floating poi - (ALView *)al_commonSuperviewOfViews; - (BOOL)al_containsMinimumNumberOfViews:(NSUInteger)minimumNumberOfViews; -- (NSArray *)al_copyViewsOnly; +- (__NSArray_of(ALView *) *)al_copyViewsOnly; @end @@ -68,6 +67,14 @@ static const CGFloat kMULTIPLIER_MIN_VALUE = 0.00001; // very small floating poi */ @interface NSLayoutConstraint (PureLayoutInternal) ++ (BOOL)al_preventAutomaticConstraintInstallation; ++ (__NSMutableArray_of(NSLayoutConstraint *) *)al_currentArrayOfCreatedConstraints; ++ (BOOL)al_isExecutingPriorityConstraintsBlock; ++ (ALLayoutPriority)al_currentGlobalConstraintPriority; +#if __PureLayout_MinBaseSDK_iOS_8_0 || __PureLayout_MinBaseSDK_OSX_10_10 ++ (NSString *)al_currentGlobalConstraintIdentifier; +#endif /* __PureLayout_MinBaseSDK_iOS_8_0 || __PureLayout_MinBaseSDK_OSX_10_10 */ ++ (void)al_applyGlobalStateToConstraint:(NSLayoutConstraint *)constraint; + (NSLayoutAttribute)al_layoutAttributeForAttribute:(ALAttribute)attribute; + (ALLayoutConstraintAxis)al_constraintAxisForAxis:(ALAxis)axis; #if __PureLayout_MinBaseSDK_iOS_8_0 @@ -76,3 +83,5 @@ static const CGFloat kMULTIPLIER_MIN_VALUE = 0.00001; // very small floating poi #endif /* __PureLayout_MinBaseSDK_iOS_8_0 */ @end + +__PL_ASSUME_NONNULL_END diff --git a/TableViewCellWithAutoLayout/PureLayout/PureLayout.h b/Pods/PureLayout/PureLayout/PureLayout/PureLayout.h similarity index 85% rename from TableViewCellWithAutoLayout/PureLayout/PureLayout.h rename to Pods/PureLayout/PureLayout/PureLayout/PureLayout.h index 8c47775..ed9b416 100755 --- a/TableViewCellWithAutoLayout/PureLayout/PureLayout.h +++ b/Pods/PureLayout/PureLayout/PureLayout/PureLayout.h @@ -1,6 +1,5 @@ // // PureLayout.h -// v2.0.5 // https://github.com/smileyborg/PureLayout // // Copyright (c) 2014-2015 Tyler Fox @@ -29,6 +28,14 @@ #ifndef PureLayout_h #define PureLayout_h +#import + +//! Project version number for PureLayout. +FOUNDATION_EXPORT double PureLayoutVersionNumber; + +//! Project version string for PureLayout. +FOUNDATION_EXPORT const unsigned char PureLayoutVersionString[]; + #import "ALView+PureLayout.h" #import "NSArray+PureLayout.h" #import "NSLayoutConstraint+PureLayout.h" diff --git a/TableViewCellWithAutoLayout/PureLayout/PureLayoutDefines.h b/Pods/PureLayout/PureLayout/PureLayout/PureLayoutDefines.h similarity index 80% rename from TableViewCellWithAutoLayout/PureLayout/PureLayoutDefines.h rename to Pods/PureLayout/PureLayout/PureLayout/PureLayoutDefines.h index 2f10152..46f4ffe 100755 --- a/TableViewCellWithAutoLayout/PureLayout/PureLayoutDefines.h +++ b/Pods/PureLayout/PureLayout/PureLayout/PureLayoutDefines.h @@ -1,6 +1,5 @@ // // PureLayoutDefines.h -// v2.0.5 // https://github.com/smileyborg/PureLayout // // Copyright (c) 2014-2015 Tyler Fox @@ -31,16 +30,37 @@ #import -#define __PureLayout_MinBaseSDK_iOS_8_0 TARGET_OS_IPHONE && __IPHONE_OS_VERSION_MAX_ALLOWED > __IPHONE_7_1 -#define __PureLayout_MinSysVer_iOS_7_0 TARGET_OS_IPHONE && floor(NSFoundationVersionNumber) > NSFoundationVersionNumber_iOS_6_1 -#define __PureLayout_MinSysVer_iOS_8_0 TARGET_OS_IPHONE && floor(NSFoundationVersionNumber) > NSFoundationVersionNumber_iOS_7_1 +// Define some preprocessor macros to check for a minimum Base SDK. These are used to prevent compile-time errors in older versions of Xcode. +#define __PureLayout_MinBaseSDK_iOS_8_0 (TARGET_OS_IPHONE && __IPHONE_OS_VERSION_MAX_ALLOWED > __IPHONE_7_1) +#define __PureLayout_MinBaseSDK_OSX_10_10 (!TARGET_OS_IPHONE && __MAC_OS_X_VERSION_MAX_ALLOWED > __MAC_10_9) -#define __PureLayout_MinBaseSDK_OSX_10_10 !TARGET_OS_IPHONE && __MAC_OS_X_VERSION_MAX_ALLOWED > __MAC_10_9 -#define __PureLayout_MinSysVer_OSX_10_9 !TARGET_OS_IPHONE && floor(NSFoundationVersionNumber) > NSFoundationVersionNumber10_8_4 +// Define some preprocessor macros to check for a minimum System Version. These are used to prevent runtime crashes on older versions of iOS/OS X. +#define __PureLayout_MinSysVer_iOS_7_0 (TARGET_OS_IPHONE && floor(NSFoundationVersionNumber) > NSFoundationVersionNumber_iOS_6_1) +#define __PureLayout_MinSysVer_iOS_8_0 (TARGET_OS_IPHONE && floor(NSFoundationVersionNumber) > NSFoundationVersionNumber_iOS_7_1) +#define __PureLayout_MinSysVer_OSX_10_9 (!TARGET_OS_IPHONE && floor(NSFoundationVersionNumber) > NSFoundationVersionNumber10_8_4) +// Define some preprocessor macros that allow nullability annotations to be adopted in a backwards-compatible manner. +#if __has_feature(nullability) +# define __PL_ASSUME_NONNULL_BEGIN NS_ASSUME_NONNULL_BEGIN +# define __PL_ASSUME_NONNULL_END NS_ASSUME_NONNULL_END +#else +# define __PL_ASSUME_NONNULL_BEGIN +# define __PL_ASSUME_NONNULL_END +#endif + +// Define some preprocessor macros that allow generics to be adopted in a backwards-compatible manner. +#if __has_feature(objc_generics) +# define __PL_GENERICS(class, ...) class<__VA_ARGS__> +#else +# define __PL_GENERICS(class, ...) class +#endif + +// Using generics with NSArray is so common in PureLayout that it gets a dedicated preprocessor macro for better readability. +#define __NSArray_of(type) __PL_GENERICS(NSArray, type) + +// Define generic AL-prefixed macros for the types/constants/etc that have slight naming variations across iOS and OS X, which allows the same code to be platform-independent. #if TARGET_OS_IPHONE # import - # define ALView UIView # define ALEdgeInsets UIEdgeInsets # define ALEdgeInsetsZero UIEdgeInsetsZero @@ -59,7 +79,6 @@ # define ALLayoutPriorityFittingSizeCompression ALLayoutPriorityFittingSizeLevel #else # import - # define ALView NSView # define ALEdgeInsets NSEdgeInsets # define ALEdgeInsetsZero NSEdgeInsetsMake(0, 0, 0, 0) @@ -107,9 +126,9 @@ typedef NS_ENUM(NSInteger, ALDimension) { /** Constants that represent axes of a view. */ typedef NS_ENUM(NSInteger, ALAxis) { - /** A vertical line through the middle of the view's left and right edges. */ + /** A vertical line equidistant from the view's left and right edges. */ ALAxisVertical = NSLayoutAttributeCenterX, - /** A horizontal line through the middle of the view's top and bottom edges. */ + /** A horizontal line equidistant from the view's top and bottom edges. */ ALAxisHorizontal = NSLayoutAttributeCenterY, /** A horizontal line at the baseline of the last line of text in the view. (For views that do not draw text, will be equivalent to ALEdgeBottom.) Same as ALAxisLastBaseline. */ @@ -142,9 +161,9 @@ typedef NS_ENUM(NSInteger, ALMargin) { /** Constants that represent axes of the layout margins of a view. Available in iOS 8.0 and later. */ typedef NS_ENUM(NSInteger, ALMarginAxis) { - /** A vertical line through the middle of the view's left and right margins. */ + /** A vertical line equidistant from the view's left and right margins. */ ALMarginAxisVertical = NSLayoutAttributeCenterXWithinMargins, - /** A horizontal line through the middle of the view's top and bottom margins. */ + /** A horizontal line equidistant from the view's top and bottom margins. */ ALMarginAxisHorizontal = NSLayoutAttributeCenterYWithinMargins }; @@ -169,9 +188,9 @@ typedef NS_ENUM(NSInteger, ALAttribute) { ALAttributeWidth = ALDimensionWidth, /** The height of the view. */ ALAttributeHeight = ALDimensionHeight, - /** A vertical line through the middle of the view's left and right edges. */ + /** A vertical line equidistant from the view's left and right edges. */ ALAttributeVertical = ALAxisVertical, - /** A horizontal line through the middle of the view's top and bottom edges. */ + /** A horizontal line equidistant from the view's top and bottom edges. */ ALAttributeHorizontal = ALAxisHorizontal, /** A horizontal line at the baseline of the last line of text in the view. (For views that do not draw text, will be equivalent to ALEdgeBottom.) Same as ALAxisLastBaseline. */ ALAttributeBaseline = ALAxisBaseline, @@ -192,9 +211,9 @@ typedef NS_ENUM(NSInteger, ALAttribute) { ALAttributeMarginLeading = ALMarginLeading, /** The trailing margin of the view, based on the view's layoutMargins left/right (depending on language direction) inset. */ ALAttributeMarginTrailing = ALMarginTrailing, - /** A vertical line through the middle of the view's left and right margins. */ + /** A vertical line equidistant from the view's left and right margins. */ ALAttributeMarginAxisVertical = ALMarginAxisVertical, - /** A horizontal line through the middle of the view's top and bottom margins. */ + /** A horizontal line equidistant from the view's top and bottom margins. */ ALAttributeMarginAxisHorizontal = ALMarginAxisHorizontal #endif /* __PureLayout_MinBaseSDK_iOS_8_0 */ }; diff --git a/Pods/PureLayout/README.md b/Pods/PureLayout/README.md new file mode 100644 index 0000000..64a8611 --- /dev/null +++ b/Pods/PureLayout/README.md @@ -0,0 +1,219 @@ +# [![PureLayout](https://github.com/smileyborg/PureLayout/blob/master/Images/PureLayout.png?raw=true)](#) +[![Build Status](http://img.shields.io/travis/smileyborg/PureLayout.svg?style=flat)](https://travis-ci.org/smileyborg/PureLayout) [![Test Coverage](http://img.shields.io/coveralls/smileyborg/PureLayout.svg?style=flat)](https://coveralls.io/r/smileyborg/PureLayout) [![Version](http://img.shields.io/cocoapods/v/PureLayout.svg?style=flat)](http://cocoapods.org/?q=PureLayout) [![Platform](http://img.shields.io/cocoapods/p/PureLayout.svg?style=flat)](http://cocoapods.org/?q=PureLayout) [![License](http://img.shields.io/cocoapods/l/PureLayout.svg?style=flat)](LICENSE) + +The ultimate API for iOS & OS X Auto Layout — impressively simple, immensely powerful. PureLayout extends `UIView`/`NSView`, `NSArray`, and `NSLayoutConstraint` with a comprehensive Auto Layout API that is modeled after Apple's own frameworks. PureLayout is a cross-platform Objective-C library that works (and looks!) great in Swift. It is fully backwards-compatible with all versions of iOS and OS X that support Auto Layout. + +Writing Auto Layout code from scratch isn't easy. PureLayout provides a fully capable and developer-friendly interface for Auto Layout. It is designed for clarity and simplicity, and takes inspiration from the AutoLayout UI options available in Interface Builder while delivering far more flexibility. The API is also highly efficient, as it adds only a thin layer of third party code and is engineered for maximum performance. + +### Table of Contents + 1. [Setup](#setup) + 1. [API Cheat Sheet](#api-cheat-sheet) + 1. [Usage](#usage) + * [Sample Code](#sample-code-swift) + * [Example Apps](#example-apps) + 1. [PureLayout vs. the rest](#purelayout-vs-the-rest) + 1. [Problems, Suggestions, Pull Requests?](#problems-suggestions-pull-requests) + +## Setup +### Compatibility +The current release of PureLayout supports all versions of iOS and OS X since the introduction of Auto Layout on each platform, in both Swift and Objective-C, with a single codebase! + +* Xcode + * Language Support: **Swift** *(any version)*, **Objective-C** + * Fully Compatible With: **Xcode 7.0** + * Minimum Supported Version: **Xcode 5.0** +* iOS + * Fully Compatible With: **iOS 9.0** + * Minimum Deployment Target: **iOS 6.0** +* OS X + * Fully Compatible With: **OS X 10.11** + * Minimum Deployment Target: **OS X 10.7** + +### Using [CocoaPods](http://cocoapods.org) +1. Add the pod `PureLayout` to your [Podfile](http://guides.cocoapods.org/using/the-podfile.html). + + ```ruby + pod 'PureLayout' + ``` + +1. Run `pod install` from Terminal, then open your app's `.xcworkspace` file to launch Xcode. +1. Import the `PureLayout.h` umbrella header. + * With `use_frameworks!` in your Podfile + * Swift: `import PureLayout` + * Objective-C: `#import ` (or with Modules enabled: `@import PureLayout;`) + * Without `use_frameworks!` in your Podfile + * Swift: Add `#import "PureLayout.h"` to your bridging header. + * Objective-C: `#import "PureLayout.h"` + +That's it - now go write some beautiful Auto Layout code! + +### Using [Carthage](https://github.com/Carthage/Carthage) +1. Add the `smileyborg/PureLayout` project to your [Cartfile](https://github.com/Carthage/Carthage/blob/master/Documentation/Artifacts.md#cartfile). + + ```ogdl + github "smileyborg/PureLayout" + ``` + +1. Run `carthage update`, then follow the [additional steps required](https://github.com/Carthage/Carthage#adding-frameworks-to-an-application) to add the framework into your project. +1. Import the PureLayout framework/module. + * Swift: `import PureLayout` + * Objective-C: `#import ` (or with Modules enabled: `@import PureLayout;`) + +That's it - now go write some beautiful Auto Layout code! + +### Manually from GitHub +1. Download the source files in the [PureLayout subdirectory](PureLayout/PureLayout). +1. Add the source files to your Xcode project. +1. Import the `PureLayout.h` header. + * Swift: Add `#import "PureLayout.h"` to your bridging header. + * Objective-C: `#import "PureLayout.h"` + +That's it - now go write some beautiful Auto Layout code! + +### App Extensions +To use PureLayout in an App Extension, you need to do a bit of extra configuration to prevent usage of unavailable APIs. [Click here](https://github.com/smileyborg/PureLayout/wiki/App-Extensions) for more info. + +### Releases +Releases are tagged in the git commit history using [semantic versioning](http://semver.org). Check out the [releases and release notes](https://github.com/smileyborg/PureLayout/releases) for each version. + +## API Cheat Sheet +This is just a handy overview of the core API methods. Explore the [header files](PureLayout/PureLayout) for the full API, and find the complete documentation above the implementation of each method in the corresponding .m file. A couple of notes: + +* All of the public API methods are namespaced with the prefix `auto...`, which also makes it easy for Xcode to autocomplete as you type. +* Methods that create constraints also automatically install (activate) the constraint(s), then return the new constraint(s) for you to optionally store for later adjustment or removal. +* Many methods below also have a variant which includes a `relation:` parameter to make the constraint an inequality. + +### Attributes + +PureLayout defines view attributes that are used to create auto layout constraints. Here is an [illustration of the most common attributes](Images/PureLayout-CommonAttributes.png). + +There are 5 specific attribute types, which are used throughout most of the API: + +* `ALEdge` +* `ALDimension` +* `ALAxis` +* `ALMargin` *available in iOS 8.0 and higher only* +* `ALMarginAxis` *available in iOS 8.0 and higher only* + +Additionally, there is one generic attribute type, `ALAttribute`, which is effectively a union of all the specific types. You can think of this as the "supertype" of all of the specific attribute types, which means that it is always safe to cast a specific type to the generic `ALAttribute` type. (Note that the reverse is not true -- casting a generic ALAttribute to a specific attribute type is unsafe!) + +### [`UIView`/`NSView`](PureLayout/PureLayout/ALView%2BPureLayout.h) +``` +- autoSetContent(CompressionResistance|Hugging)PriorityForAxis: +- autoCenterInSuperview(Margins): // Margins variant iOS 8.0+ only +- autoAlignAxisToSuperview(Margin)Axis: // Margin variant iOS 8.0+ only +- autoPinEdgeToSuperview(Edge:|Margin:)(withInset:) // Margin variant iOS 8.0+ only +- autoPinEdgesToSuperview(Edges|Margins)(WithInsets:)(excludingEdge:) // Margins variant iOS 8.0+ only +- autoPinEdge:toEdge:ofView:(withOffset:) +- autoAlignAxis:toSameAxisOfView:(withOffset:|withMultiplier:) +- autoMatchDimension:toDimension:ofView:(withOffset:|withMultiplier:) +- autoSetDimension(s)ToSize: +- autoConstrainAttribute:toAttribute:ofView:(withOffset:|withMultiplier:) +- autoPinTo(Top|Bottom)LayoutGuideOfViewController:withInset: // iOS only +``` + +### [`NSArray`](PureLayout/PureLayout/NSArray%2BPureLayout.h) +``` +// Arrays of Constraints +- autoInstallConstraints +- autoRemoveConstraints +- autoIdentifyConstraints: // iOS 7.0+, OS X 10.9+ only + +// Arrays of Views +- autoAlignViewsToEdge: +- autoAlignViewsToAxis: +- autoMatchViewsDimension: +- autoSetViewsDimension:toSize: +- autoSetViewsDimensionsToSize: +- autoDistributeViewsAlongAxis:alignedTo:withFixedSpacing:(insetSpacing:)(matchedSizes:) +- autoDistributeViewsAlongAxis:alignedTo:withFixedSize:(insetSpacing:) +``` + +### [`NSLayoutConstraint`](PureLayout/PureLayout/NSLayoutConstraint%2BPureLayout.h) +``` ++ autoCreateAndInstallConstraints: ++ autoCreateConstraintsWithoutInstalling: ++ autoSetPriority:forConstraints: ++ autoSetIdentifier:forConstraints: // iOS 7.0+, OS X 10.9+ only +- autoIdentify: // iOS 7.0+, OS X 10.9+ only +- autoInstall +- autoRemove +``` + +## Usage +### Sample Code (Swift) +PureLayout dramatically simplifies writing Auto Layout code. Let's take a quick look at some examples, using PureLayout from Swift. + +Here's a constraint between two views created (and automatically activated) using PureLayout: + +```swift +view1.autoPinEdge(.Top, toEdge: .Bottom, ofView: view2) +``` + +Without PureLayout, here's the equivalent code you'd have to write using Apple's Foundation API directly: + +```swift +NSLayoutConstraint(item: view1, attribute: .Top, relatedBy: .Equal, toItem: view2, attribute: .Bottom, multiplier: 1.0, constant: 0.0).active = true +``` + +Many APIs of PureLayout create multiple constraints for you under the hood, letting you write highly readable layout code: + +```swift +// 2 constraints created & activated in one line! +logoImageView.autoCenterInSuperview() + +// 4 constraints created & activated in one line! +textContentView.autoPinEdgesToSuperviewEdgesWithInsets(UIEdgeInsets(top: 20.0, left: 5.0, bottom: 10.0, right: 5.0)) +``` + +PureLayout always returns the constraints it creates so you have full control: + +```swift +let constraint = skinnyView.autoMatchDimension(.Height, toDimension: .Width, ofView: tallView) +``` + +PureLayout supports all Auto Layout features including inequalities, priorities, layout margins, identifiers, and much more. It's a comprehensive, developer-friendly way to use Auto Layout. + +Check out the example apps below for many more demos of PureLayout in use. + +### Example Apps +Open the project included in the repository (requires Xcode 6 or higher). It contains [iOS](PureLayout/Example-iOS) (`Example-iOS` scheme) and [OS X](PureLayout/Example-Mac) (`Example-Mac` scheme) demos of the library being used in various scenarios. The demos in the iOS example app make a great introductory tutorial to PureLayout -- run each demo, review the code used to implement it, then practice by making some changes of your own to the demo code. + +Each demo in the iOS example app has a Swift and Objective-C version. **To compile & run the Swift demos, you must use Xcode 7.0 or higher (Swift 2.0) and choose the `Example-iOS-Xcode7` scheme.** When you run the example app, you can easily switch between using the Swift and Objective-C versions of the demos. To see the constraints in action while running the iOS demos, try using different device simulators, rotating the device to different orientations, as well as toggling the taller in-call status bar in the iOS Simulator. + +On OS X, while running the app, press any key to cycle through the demos. You can resize the window to see the constraints in action. + +### Tips and Tricks +Check out some [Tips and Tricks](https://github.com/smileyborg/PureLayout/wiki/Tips-and-Tricks) to keep in mind when using the API. + +## PureLayout vs. the rest +There are quite a few different ways to implement Auto Layout. Here is a quick overview of the available options: + +* Apple [NSLayoutConstraint SDK API](https://developer.apple.com/library/ios/documentation/AppKit/Reference/NSLayoutConstraint_Class/index.html#//apple_ref/occ/clm/NSLayoutConstraint/constraintWithItem:attribute:relatedBy:toItem:attribute:multiplier:constant:) + * Pros: Raw power + * Cons: Extremely verbose; tedious to write; difficult to read +* Apple [Visual Format Language](https://developer.apple.com/library/ios/documentation/UserExperience/Conceptual/AutolayoutPG/VisualFormatLanguage/VisualFormatLanguage.html) + * Pros: Concise; convenient + * Cons: Doesn't support some use cases; lacks compile-time checking and safety; must learn syntax; hard to debug +* Apple Interface Builder + * Pros: Visual; interactive; provides compile-time layout checking + * Cons: Difficult for complex layouts; cannot dynamically set constraints at runtime; encourages hardcoded magic numbers; not always WYSIWYG +* Apple [NSLayoutAnchor SDK API](https://developer.apple.com/library/prerelease/ios/documentation/AppKit/Reference/NSLayoutAnchor_ClassReference/index.html) + * Pros: Clean, readable, and type-safe API for creating individual constraints + * Cons: Only available in iOS 9.0 and OS X 10.11 and higher; requires manually activating each constraint; no API for creating multiple constraints at once +* **PureLayout** + * Pros: Compatible with Objective-C and Swift codebases; consistent with Cocoa API style; cross-platform API and implementation shared across iOS and OS X; fully backwards-compatible to iOS 6 & OS X 10.7; easy to use; type-safe; efficient + * Cons: Not the most concise expression of layout code +* High-level Auto Layout Libraries/DSLs ([Cartography](https://github.com/robb/Cartography), [SnapKit](https://github.com/SnapKit/SnapKit), [KeepLayout](https://github.com/iMartinKiss/KeepLayout)) + * Pros: Very clean, concise, and convenient + * Cons: Unique API style is foreign to Apple's APIs; mixed compatibility with Objective-C & Swift; greater dependency on third party code + +PureLayout takes a balanced approach to Auto Layout that makes it well suited for any project. + +## Problems, Suggestions, Pull Requests? +Please open a [new Issue here](https://github.com/smileyborg/PureLayout/issues/new) if you run into a problem specific to PureLayout, have a feature request, or want to share a comment. Note that general Auto Layout questions should be asked on [Stack Overflow](http://stackoverflow.com). + +Pull requests are encouraged and greatly appreciated! Please try to maintain consistency with the existing code style. If you're considering taking on significant changes or additions to the project, please communicate in advance by opening a new Issue. This allows everyone to get onboard with upcoming changes, ensures that changes align with the project's design philosophy, and avoids duplicated work. + +## Meta +Designed & maintained by Tyler Fox ([@smileyborg](https://twitter.com/smileyborg)). Distributed with the MIT license. diff --git a/Pods/Target Support Files/Pods/Info.plist b/Pods/Target Support Files/Pods/Info.plist new file mode 100644 index 0000000..6974542 --- /dev/null +++ b/Pods/Target Support Files/Pods/Info.plist @@ -0,0 +1,26 @@ + + + + + CFBundleDevelopmentRegion + en + CFBundleExecutable + ${EXECUTABLE_NAME} + CFBundleIdentifier + org.cocoapods.${PRODUCT_NAME:rfc1034identifier} + CFBundleInfoDictionaryVersion + 6.0 + CFBundleName + ${PRODUCT_NAME} + CFBundlePackageType + FMWK + CFBundleShortVersionString + 1.0.0 + CFBundleSignature + ???? + CFBundleVersion + ${CURRENT_PROJECT_VERSION} + NSPrincipalClass + + + diff --git a/Pods/Target Support Files/Pods/Pods-acknowledgements.markdown b/Pods/Target Support Files/Pods/Pods-acknowledgements.markdown new file mode 100644 index 0000000..3d79025 --- /dev/null +++ b/Pods/Target Support Files/Pods/Pods-acknowledgements.markdown @@ -0,0 +1,16 @@ +# Acknowledgements +This application makes use of the following third party libraries: + +## PureLayout + +This code is distributed under the terms and conditions of the MIT license. + +Copyright (c) 2014-2015 Tyler Fox + +Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + +Generated by CocoaPods - http://cocoapods.org diff --git a/Pods/Target Support Files/Pods/Pods-acknowledgements.plist b/Pods/Target Support Files/Pods/Pods-acknowledgements.plist new file mode 100644 index 0000000..26ec4e4 --- /dev/null +++ b/Pods/Target Support Files/Pods/Pods-acknowledgements.plist @@ -0,0 +1,46 @@ + + + + + PreferenceSpecifiers + + + FooterText + This application makes use of the following third party libraries: + Title + Acknowledgements + Type + PSGroupSpecifier + + + FooterText + This code is distributed under the terms and conditions of the MIT license. + +Copyright (c) 2014-2015 Tyler Fox + +Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + + Title + PureLayout + Type + PSGroupSpecifier + + + FooterText + Generated by CocoaPods - http://cocoapods.org + Title + + Type + PSGroupSpecifier + + + StringsTable + Acknowledgements + Title + Acknowledgements + + diff --git a/Pods/Target Support Files/Pods/Pods-dummy.m b/Pods/Target Support Files/Pods/Pods-dummy.m new file mode 100644 index 0000000..ade64bd --- /dev/null +++ b/Pods/Target Support Files/Pods/Pods-dummy.m @@ -0,0 +1,5 @@ +#import +@interface PodsDummy_Pods : NSObject +@end +@implementation PodsDummy_Pods +@end diff --git a/Pods/Target Support Files/Pods/Pods-frameworks.sh b/Pods/Target Support Files/Pods/Pods-frameworks.sh new file mode 100755 index 0000000..212af00 --- /dev/null +++ b/Pods/Target Support Files/Pods/Pods-frameworks.sh @@ -0,0 +1,59 @@ +#!/bin/sh +set -e + +echo "mkdir -p ${CONFIGURATION_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}" +mkdir -p "${CONFIGURATION_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}" + +SWIFT_STDLIB_PATH="${DT_TOOLCHAIN_DIR}/usr/lib/swift/${PLATFORM_NAME}" + +install_framework() +{ + if [ -r "${BUILT_PRODUCTS_DIR}/$1" ]; then + local source="${BUILT_PRODUCTS_DIR}/$1" + else + local source="${BUILT_PRODUCTS_DIR}/$(basename "$1")" + fi + + local destination="${CONFIGURATION_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}" + + if [ -L "${source}" ]; then + echo "Symlinked..." + source="$(readlink "${source}")" + fi + + # use filter instead of exclude so missing patterns dont' throw errors + echo "rsync -av --filter \"- CVS/\" --filter \"- .svn/\" --filter \"- .git/\" --filter \"- .hg/\" --filter \"- Headers\" --filter \"- PrivateHeaders\" --filter \"- Modules\" \"${source}\" \"${destination}\"" + rsync -av --filter "- CVS/" --filter "- .svn/" --filter "- .git/" --filter "- .hg/" --filter "- Headers" --filter "- PrivateHeaders" --filter "- Modules" "${source}" "${destination}" + + # Resign the code if required by the build settings to avoid unstable apps + code_sign_if_enabled "${destination}/$(basename "$1")" + + # Embed linked Swift runtime libraries + local basename + basename="$(basename "$1" | sed -E s/\\..+// && exit ${PIPESTATUS[0]})" + local swift_runtime_libs + swift_runtime_libs=$(xcrun otool -LX "${CONFIGURATION_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/${basename}.framework/${basename}" | grep --color=never @rpath/libswift | sed -E s/@rpath\\/\(.+dylib\).*/\\1/g | uniq -u && exit ${PIPESTATUS[0]}) + for lib in $swift_runtime_libs; do + echo "rsync -auv \"${SWIFT_STDLIB_PATH}/${lib}\" \"${destination}\"" + rsync -auv "${SWIFT_STDLIB_PATH}/${lib}" "${destination}" + code_sign_if_enabled "${destination}/${lib}" + done +} + +# Signs a framework with the provided identity +code_sign_if_enabled() { + if [ -n "${EXPANDED_CODE_SIGN_IDENTITY}" -a "${CODE_SIGNING_REQUIRED}" != "NO" -a "${CODE_SIGNING_ALLOWED}" != "NO" ]; then + # Use the current code_sign_identitiy + echo "Code Signing $1 with Identity ${EXPANDED_CODE_SIGN_IDENTITY_NAME}" + echo "/usr/bin/codesign --force --sign ${EXPANDED_CODE_SIGN_IDENTITY} --preserve-metadata=identifier,entitlements \"$1\"" + /usr/bin/codesign --force --sign ${EXPANDED_CODE_SIGN_IDENTITY} --preserve-metadata=identifier,entitlements "$1" + fi +} + + +if [[ "$CONFIGURATION" == "Debug" ]]; then + install_framework 'Pods/PureLayout.framework' +fi +if [[ "$CONFIGURATION" == "Release" ]]; then + install_framework 'Pods/PureLayout.framework' +fi diff --git a/Pods/Target Support Files/Pods/Pods-resources.sh b/Pods/Target Support Files/Pods/Pods-resources.sh new file mode 100755 index 0000000..ea685a2 --- /dev/null +++ b/Pods/Target Support Files/Pods/Pods-resources.sh @@ -0,0 +1,95 @@ +#!/bin/sh +set -e + +mkdir -p "${CONFIGURATION_BUILD_DIR}/${UNLOCALIZED_RESOURCES_FOLDER_PATH}" + +RESOURCES_TO_COPY=${PODS_ROOT}/resources-to-copy-${TARGETNAME}.txt +> "$RESOURCES_TO_COPY" + +XCASSET_FILES=() + +realpath() { + DIRECTORY="$(cd "${1%/*}" && pwd)" + FILENAME="${1##*/}" + echo "$DIRECTORY/$FILENAME" +} + +install_resource() +{ + case $1 in + *.storyboard) + echo "ibtool --reference-external-strings-file --errors --warnings --notices --output-format human-readable-text --compile ${CONFIGURATION_BUILD_DIR}/${UNLOCALIZED_RESOURCES_FOLDER_PATH}/`basename \"$1\" .storyboard`.storyboardc ${PODS_ROOT}/$1 --sdk ${SDKROOT}" + ibtool --reference-external-strings-file --errors --warnings --notices --output-format human-readable-text --compile "${CONFIGURATION_BUILD_DIR}/${UNLOCALIZED_RESOURCES_FOLDER_PATH}/`basename \"$1\" .storyboard`.storyboardc" "${PODS_ROOT}/$1" --sdk "${SDKROOT}" + ;; + *.xib) + echo "ibtool --reference-external-strings-file --errors --warnings --notices --output-format human-readable-text --compile ${CONFIGURATION_BUILD_DIR}/${UNLOCALIZED_RESOURCES_FOLDER_PATH}/`basename \"$1\" .xib`.nib ${PODS_ROOT}/$1 --sdk ${SDKROOT}" + ibtool --reference-external-strings-file --errors --warnings --notices --output-format human-readable-text --compile "${CONFIGURATION_BUILD_DIR}/${UNLOCALIZED_RESOURCES_FOLDER_PATH}/`basename \"$1\" .xib`.nib" "${PODS_ROOT}/$1" --sdk "${SDKROOT}" + ;; + *.framework) + echo "mkdir -p ${CONFIGURATION_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}" + mkdir -p "${CONFIGURATION_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}" + echo "rsync -av ${PODS_ROOT}/$1 ${CONFIGURATION_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}" + rsync -av "${PODS_ROOT}/$1" "${CONFIGURATION_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}" + ;; + *.xcdatamodel) + echo "xcrun momc \"${PODS_ROOT}/$1\" \"${CONFIGURATION_BUILD_DIR}/${UNLOCALIZED_RESOURCES_FOLDER_PATH}/`basename "$1"`.mom\"" + xcrun momc "${PODS_ROOT}/$1" "${CONFIGURATION_BUILD_DIR}/${UNLOCALIZED_RESOURCES_FOLDER_PATH}/`basename "$1" .xcdatamodel`.mom" + ;; + *.xcdatamodeld) + echo "xcrun momc \"${PODS_ROOT}/$1\" \"${CONFIGURATION_BUILD_DIR}/${UNLOCALIZED_RESOURCES_FOLDER_PATH}/`basename "$1" .xcdatamodeld`.momd\"" + xcrun momc "${PODS_ROOT}/$1" "${CONFIGURATION_BUILD_DIR}/${UNLOCALIZED_RESOURCES_FOLDER_PATH}/`basename "$1" .xcdatamodeld`.momd" + ;; + *.xcmappingmodel) + echo "xcrun mapc \"${PODS_ROOT}/$1\" \"${CONFIGURATION_BUILD_DIR}/${UNLOCALIZED_RESOURCES_FOLDER_PATH}/`basename "$1" .xcmappingmodel`.cdm\"" + xcrun mapc "${PODS_ROOT}/$1" "${CONFIGURATION_BUILD_DIR}/${UNLOCALIZED_RESOURCES_FOLDER_PATH}/`basename "$1" .xcmappingmodel`.cdm" + ;; + *.xcassets) + ABSOLUTE_XCASSET_FILE=$(realpath "${PODS_ROOT}/$1") + XCASSET_FILES+=("$ABSOLUTE_XCASSET_FILE") + ;; + /*) + echo "$1" + echo "$1" >> "$RESOURCES_TO_COPY" + ;; + *) + echo "${PODS_ROOT}/$1" + echo "${PODS_ROOT}/$1" >> "$RESOURCES_TO_COPY" + ;; + esac +} + +mkdir -p "${CONFIGURATION_BUILD_DIR}/${UNLOCALIZED_RESOURCES_FOLDER_PATH}" +rsync -avr --copy-links --no-relative --exclude '*/.svn/*' --files-from="$RESOURCES_TO_COPY" / "${CONFIGURATION_BUILD_DIR}/${UNLOCALIZED_RESOURCES_FOLDER_PATH}" +if [[ "${ACTION}" == "install" ]]; then + mkdir -p "${INSTALL_DIR}/${UNLOCALIZED_RESOURCES_FOLDER_PATH}" + rsync -avr --copy-links --no-relative --exclude '*/.svn/*' --files-from="$RESOURCES_TO_COPY" / "${INSTALL_DIR}/${UNLOCALIZED_RESOURCES_FOLDER_PATH}" +fi +rm -f "$RESOURCES_TO_COPY" + +if [[ -n "${WRAPPER_EXTENSION}" ]] && [ "`xcrun --find actool`" ] && [ -n "$XCASSET_FILES" ] +then + case "${TARGETED_DEVICE_FAMILY}" in + 1,2) + TARGET_DEVICE_ARGS="--target-device ipad --target-device iphone" + ;; + 1) + TARGET_DEVICE_ARGS="--target-device iphone" + ;; + 2) + TARGET_DEVICE_ARGS="--target-device ipad" + ;; + *) + TARGET_DEVICE_ARGS="--target-device mac" + ;; + esac + + # Find all other xcassets (this unfortunately includes those of path pods and other targets). + OTHER_XCASSETS=$(find "$PWD" -iname "*.xcassets" -type d) + while read line; do + if [[ $line != "`realpath $PODS_ROOT`*" ]]; then + XCASSET_FILES+=("$line") + fi + done <<<"$OTHER_XCASSETS" + + printf "%s\0" "${XCASSET_FILES[@]}" | xargs -0 xcrun actool --output-format human-readable-text --notices --warnings --platform "${PLATFORM_NAME}" --minimum-deployment-target "${IPHONEOS_DEPLOYMENT_TARGET}" ${TARGET_DEVICE_ARGS} --compress-pngs --compile "${BUILT_PRODUCTS_DIR}/${UNLOCALIZED_RESOURCES_FOLDER_PATH}" +fi diff --git a/Pods/Target Support Files/Pods/Pods-umbrella.h b/Pods/Target Support Files/Pods/Pods-umbrella.h new file mode 100644 index 0000000..21dcfd2 --- /dev/null +++ b/Pods/Target Support Files/Pods/Pods-umbrella.h @@ -0,0 +1,6 @@ +#import + + +FOUNDATION_EXPORT double PodsVersionNumber; +FOUNDATION_EXPORT const unsigned char PodsVersionString[]; + diff --git a/Pods/Target Support Files/Pods/Pods.debug.xcconfig b/Pods/Target Support Files/Pods/Pods.debug.xcconfig new file mode 100644 index 0000000..eb4d3d2 --- /dev/null +++ b/Pods/Target Support Files/Pods/Pods.debug.xcconfig @@ -0,0 +1,6 @@ +GCC_PREPROCESSOR_DEFINITIONS = $(inherited) COCOAPODS=1 +LD_RUNPATH_SEARCH_PATHS = $(inherited) '@executable_path/Frameworks' '@loader_path/Frameworks' +OTHER_CFLAGS = $(inherited) -iquote "$CONFIGURATION_BUILD_DIR/PureLayout.framework/Headers" +OTHER_LDFLAGS = $(inherited) -framework "PureLayout" +PODS_FRAMEWORK_BUILD_PATH = $(BUILD_DIR)/$(CONFIGURATION)$(EFFECTIVE_PLATFORM_NAME)/Pods +PODS_ROOT = ${SRCROOT}/Pods \ No newline at end of file diff --git a/Pods/Target Support Files/Pods/Pods.modulemap b/Pods/Target Support Files/Pods/Pods.modulemap new file mode 100644 index 0000000..8413413 --- /dev/null +++ b/Pods/Target Support Files/Pods/Pods.modulemap @@ -0,0 +1,6 @@ +framework module Pods { + umbrella header "Pods-umbrella.h" + + export * + module * { export * } +} diff --git a/Pods/Target Support Files/Pods/Pods.release.xcconfig b/Pods/Target Support Files/Pods/Pods.release.xcconfig new file mode 100644 index 0000000..eb4d3d2 --- /dev/null +++ b/Pods/Target Support Files/Pods/Pods.release.xcconfig @@ -0,0 +1,6 @@ +GCC_PREPROCESSOR_DEFINITIONS = $(inherited) COCOAPODS=1 +LD_RUNPATH_SEARCH_PATHS = $(inherited) '@executable_path/Frameworks' '@loader_path/Frameworks' +OTHER_CFLAGS = $(inherited) -iquote "$CONFIGURATION_BUILD_DIR/PureLayout.framework/Headers" +OTHER_LDFLAGS = $(inherited) -framework "PureLayout" +PODS_FRAMEWORK_BUILD_PATH = $(BUILD_DIR)/$(CONFIGURATION)$(EFFECTIVE_PLATFORM_NAME)/Pods +PODS_ROOT = ${SRCROOT}/Pods \ No newline at end of file diff --git a/Pods/Target Support Files/PureLayout/Info.plist b/Pods/Target Support Files/PureLayout/Info.plist new file mode 100644 index 0000000..dc92af9 --- /dev/null +++ b/Pods/Target Support Files/PureLayout/Info.plist @@ -0,0 +1,26 @@ + + + + + CFBundleDevelopmentRegion + en + CFBundleExecutable + ${EXECUTABLE_NAME} + CFBundleIdentifier + org.cocoapods.${PRODUCT_NAME:rfc1034identifier} + CFBundleInfoDictionaryVersion + 6.0 + CFBundleName + ${PRODUCT_NAME} + CFBundlePackageType + FMWK + CFBundleShortVersionString + 3.0.0 + CFBundleSignature + ???? + CFBundleVersion + ${CURRENT_PROJECT_VERSION} + NSPrincipalClass + + + diff --git a/Pods/Target Support Files/PureLayout/PureLayout-Private.xcconfig b/Pods/Target Support Files/PureLayout/PureLayout-Private.xcconfig new file mode 100644 index 0000000..a7833f5 --- /dev/null +++ b/Pods/Target Support Files/PureLayout/PureLayout-Private.xcconfig @@ -0,0 +1,5 @@ +#include "PureLayout.xcconfig" +GCC_PREPROCESSOR_DEFINITIONS = $(inherited) COCOAPODS=1 +HEADER_SEARCH_PATHS = "${PODS_ROOT}/Headers/Private" "${PODS_ROOT}/Headers/Private/PureLayout" "${PODS_ROOT}/Headers/Public" +PODS_ROOT = ${SRCROOT} +SKIP_INSTALL = YES \ No newline at end of file diff --git a/Pods/Target Support Files/PureLayout/PureLayout-dummy.m b/Pods/Target Support Files/PureLayout/PureLayout-dummy.m new file mode 100644 index 0000000..de09ca1 --- /dev/null +++ b/Pods/Target Support Files/PureLayout/PureLayout-dummy.m @@ -0,0 +1,5 @@ +#import +@interface PodsDummy_PureLayout : NSObject +@end +@implementation PodsDummy_PureLayout +@end diff --git a/Pods/Target Support Files/PureLayout/PureLayout-prefix.pch b/Pods/Target Support Files/PureLayout/PureLayout-prefix.pch new file mode 100644 index 0000000..aa992a4 --- /dev/null +++ b/Pods/Target Support Files/PureLayout/PureLayout-prefix.pch @@ -0,0 +1,4 @@ +#ifdef __OBJC__ +#import +#endif + diff --git a/Pods/Target Support Files/PureLayout/PureLayout-umbrella.h b/Pods/Target Support Files/PureLayout/PureLayout-umbrella.h new file mode 100644 index 0000000..b50c609 --- /dev/null +++ b/Pods/Target Support Files/PureLayout/PureLayout-umbrella.h @@ -0,0 +1,12 @@ +#import + +#import "ALView+PureLayout.h" +#import "NSArray+PureLayout.h" +#import "NSLayoutConstraint+PureLayout.h" +#import "PureLayout+Internal.h" +#import "PureLayout.h" +#import "PureLayoutDefines.h" + +FOUNDATION_EXPORT double PureLayoutVersionNumber; +FOUNDATION_EXPORT const unsigned char PureLayoutVersionString[]; + diff --git a/Pods/Target Support Files/PureLayout/PureLayout.modulemap b/Pods/Target Support Files/PureLayout/PureLayout.modulemap new file mode 100644 index 0000000..fd62d58 --- /dev/null +++ b/Pods/Target Support Files/PureLayout/PureLayout.modulemap @@ -0,0 +1,6 @@ +framework module PureLayout { + umbrella header "PureLayout-umbrella.h" + + export * + module * { export * } +} diff --git a/Pods/Target Support Files/PureLayout/PureLayout.xcconfig b/Pods/Target Support Files/PureLayout/PureLayout.xcconfig new file mode 100644 index 0000000..e69de29 diff --git a/README.md b/README.md index adfb252..a2c434f 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ TableViewCellWithAutoLayoutiOS8 =========================== -*Note: This sample project requires __Xcode 6__ and __iOS 8__. For a sample project demonstrating the iOS 7 compatible implementation, [click here](https://github.com/smileyborg/TableViewCellWithAutoLayout).* +*Note: This sample project requires __Xcode 7__ and __iOS 8__. For a sample project demonstrating the iOS 7 compatible implementation, [click here](https://github.com/smileyborg/TableViewCellWithAutoLayout).* Sample project demonstrating self-sizing table view cells in iOS 8, using Auto Layout in UITableViewCell to achieve dynamic layouts with variable row heights. This project is a universal app that will run on iPhone and iPad. This implementation is only compatible with iOS 8 and later. @@ -10,6 +10,8 @@ There are two branches in this repository: 1. **master** (this branch) - A Swift implementation 2. **[objective-c](https://github.com/smileyborg/TableViewCellWithAutoLayoutiOS8/tree/objective-c)** - An Objective-C implementation +To build & run the app, you should open the `TableViewCellWithAutoLayout.xcworkspace` in Xcode. + This sample project displays a table view with cells that each contain a single-line title label and a multi-line body label (each cell's body label displays a random number of lorem ipsum words). This project utilizes the open source [PureLayout](https://github.com/smileyborg/PureLayout) library to easily set up constraints in code. @@ -18,4 +20,4 @@ See the original post on Stack Overflow for more info: http://stackoverflow.com/questions/18746929/using-auto-layout-in-uitableview-for-dynamic-cell-layouts-variable-row-heights -If you have questions or run into issues, please [open a new Issue on this GitHub project](https://github.com/smileyborg/TableViewCellWithAutoLayoutiOS8/issues/new) or reach out to me on Twitter [@smileyborg](https://twitter.com/smileyborg). +If you have questions or run into issues, please [open a new Issue on this GitHub project](https://github.com/smileyborg/TableViewCellWithAutoLayoutiOS8/issues/new). diff --git a/TableViewCellWithAutoLayout.xcodeproj/project.pbxproj b/TableViewCellWithAutoLayout.xcodeproj/project.pbxproj index 4873dcd..a87308f 100644 --- a/TableViewCellWithAutoLayout.xcodeproj/project.pbxproj +++ b/TableViewCellWithAutoLayout.xcodeproj/project.pbxproj @@ -9,6 +9,7 @@ /* Begin PBXBuildFile section */ 5A3B25361945F89500838EF4 /* NibTableViewCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5A3B25351945F89500838EF4 /* NibTableViewCell.swift */; }; 5A3B25381945F8AC00838EF4 /* NibTableViewCell.xib in Resources */ = {isa = PBXBuildFile; fileRef = 5A3B25371945F8AC00838EF4 /* NibTableViewCell.xib */; }; + 65C7B47C160366D672EF8E13 /* Pods.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = E94577F57ED7FB9D3081729B /* Pods.framework */; settings = {ATTRIBUTES = (Weak, ); }; }; 99BCDCA518008C0000B8E66B /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 99BCDCA418008C0000B8E66B /* Foundation.framework */; }; 99BCDCA718008C0000B8E66B /* CoreGraphics.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 99BCDCA618008C0000B8E66B /* CoreGraphics.framework */; }; 99BCDCA918008C0000B8E66B /* UIKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 99BCDCA818008C0000B8E66B /* UIKit.framework */; }; @@ -23,9 +24,6 @@ A7F5DDAA194408D9008E238B /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = A7F5DDA9194408D9008E238B /* AppDelegate.swift */; }; A7F5DDAC19440B7B008E238B /* Model.swift in Sources */ = {isa = PBXBuildFile; fileRef = A7F5DDAB19440B7B008E238B /* Model.swift */; }; A7F5DDAE194417DC008E238B /* TableViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = A7F5DDAD194417DC008E238B /* TableViewController.swift */; }; - B126BA121959EF4E0018DBAE /* ALView+PureLayout.m in Sources */ = {isa = PBXBuildFile; fileRef = B126BA0A1959EF4E0018DBAE /* ALView+PureLayout.m */; }; - B126BA131959EF4E0018DBAE /* NSArray+PureLayout.m in Sources */ = {isa = PBXBuildFile; fileRef = B126BA0C1959EF4E0018DBAE /* NSArray+PureLayout.m */; }; - B126BA141959EF4E0018DBAE /* NSLayoutConstraint+PureLayout.m in Sources */ = {isa = PBXBuildFile; fileRef = B126BA0E1959EF4E0018DBAE /* NSLayoutConstraint+PureLayout.m */; }; /* End PBXBuildFile section */ /* Begin PBXContainerItemProxy section */ @@ -39,6 +37,7 @@ /* End PBXContainerItemProxy section */ /* Begin PBXFileReference section */ + 57612988E552EA49095C8330 /* Pods.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = Pods.debug.xcconfig; path = "Pods/Target Support Files/Pods/Pods.debug.xcconfig"; sourceTree = ""; }; 5A3B25351945F89500838EF4 /* NibTableViewCell.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = NibTableViewCell.swift; sourceTree = ""; }; 5A3B25371945F8AC00838EF4 /* NibTableViewCell.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; path = NibTableViewCell.xib; sourceTree = ""; }; 99BCDCA118008C0000B8E66B /* TableViewCellWithAutoLayout.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = TableViewCellWithAutoLayout.app; sourceTree = BUILT_PRODUCTS_DIR; }; @@ -59,15 +58,8 @@ A7F5DDA9194408D9008E238B /* AppDelegate.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = ""; }; A7F5DDAB19440B7B008E238B /* Model.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Model.swift; sourceTree = ""; }; A7F5DDAD194417DC008E238B /* TableViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TableViewController.swift; sourceTree = ""; }; - B126BA091959EF4E0018DBAE /* ALView+PureLayout.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "ALView+PureLayout.h"; sourceTree = ""; }; - B126BA0A1959EF4E0018DBAE /* ALView+PureLayout.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "ALView+PureLayout.m"; sourceTree = ""; }; - B126BA0B1959EF4E0018DBAE /* NSArray+PureLayout.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "NSArray+PureLayout.h"; sourceTree = ""; }; - B126BA0C1959EF4E0018DBAE /* NSArray+PureLayout.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "NSArray+PureLayout.m"; sourceTree = ""; }; - B126BA0D1959EF4E0018DBAE /* NSLayoutConstraint+PureLayout.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "NSLayoutConstraint+PureLayout.h"; sourceTree = ""; }; - B126BA0E1959EF4E0018DBAE /* NSLayoutConstraint+PureLayout.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "NSLayoutConstraint+PureLayout.m"; sourceTree = ""; }; - B126BA0F1959EF4E0018DBAE /* PureLayout+Internal.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "PureLayout+Internal.h"; sourceTree = ""; }; - B126BA101959EF4E0018DBAE /* PureLayout.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PureLayout.h; sourceTree = ""; }; - B126BA111959EF4E0018DBAE /* PureLayoutDefines.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PureLayoutDefines.h; sourceTree = ""; }; + E8389E598E67F5F16660D9AC /* Pods.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = Pods.release.xcconfig; path = "Pods/Target Support Files/Pods/Pods.release.xcconfig"; sourceTree = ""; }; + E94577F57ED7FB9D3081729B /* Pods.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods.framework; sourceTree = BUILT_PRODUCTS_DIR; }; /* End PBXFileReference section */ /* Begin PBXFrameworksBuildPhase section */ @@ -78,6 +70,7 @@ 99BCDCA718008C0000B8E66B /* CoreGraphics.framework in Frameworks */, 99BCDCA918008C0000B8E66B /* UIKit.framework in Frameworks */, 99BCDCA518008C0000B8E66B /* Foundation.framework in Frameworks */, + 65C7B47C160366D672EF8E13 /* Pods.framework in Frameworks */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -101,6 +94,7 @@ 99BCDCC318008C0000B8E66B /* TableViewCellWithAutoLayoutTests */, 99BCDCA318008C0000B8E66B /* Frameworks */, 99BCDCA218008C0000B8E66B /* Products */, + B388C4772DBE5FA65C4D24F3 /* Pods */, ); sourceTree = ""; }; @@ -120,6 +114,7 @@ 99BCDCA618008C0000B8E66B /* CoreGraphics.framework */, 99BCDCA818008C0000B8E66B /* UIKit.framework */, 99BCDCBD18008C0000B8E66B /* XCTest.framework */, + E94577F57ED7FB9D3081729B /* Pods.framework */, ); name = Frameworks; sourceTree = ""; @@ -127,7 +122,6 @@ 99BCDCAA18008C0000B8E66B /* TableViewCellWithAutoLayout */ = { isa = PBXGroup; children = ( - B126BA081959EF4E0018DBAE /* PureLayout */, A7F5DDA9194408D9008E238B /* AppDelegate.swift */, 99BCDCB618008C0000B8E66B /* Images.xcassets */, 99BCDCD318008C1700B8E66B /* TableViewController */, @@ -176,22 +170,6 @@ path = TableViewController; sourceTree = ""; }; - B126BA081959EF4E0018DBAE /* PureLayout */ = { - isa = PBXGroup; - children = ( - B126BA091959EF4E0018DBAE /* ALView+PureLayout.h */, - B126BA0A1959EF4E0018DBAE /* ALView+PureLayout.m */, - B126BA0B1959EF4E0018DBAE /* NSArray+PureLayout.h */, - B126BA0C1959EF4E0018DBAE /* NSArray+PureLayout.m */, - B126BA0D1959EF4E0018DBAE /* NSLayoutConstraint+PureLayout.h */, - B126BA0E1959EF4E0018DBAE /* NSLayoutConstraint+PureLayout.m */, - B126BA0F1959EF4E0018DBAE /* PureLayout+Internal.h */, - B126BA101959EF4E0018DBAE /* PureLayout.h */, - B126BA111959EF4E0018DBAE /* PureLayoutDefines.h */, - ); - path = PureLayout; - sourceTree = ""; - }; B13F6E9E1947D6DE00FF3B42 /* Programmatic */ = { isa = PBXGroup; children = ( @@ -209,6 +187,15 @@ name = "Interface Builder"; sourceTree = ""; }; + B388C4772DBE5FA65C4D24F3 /* Pods */ = { + isa = PBXGroup; + children = ( + 57612988E552EA49095C8330 /* Pods.debug.xcconfig */, + E8389E598E67F5F16660D9AC /* Pods.release.xcconfig */, + ); + name = Pods; + sourceTree = ""; + }; /* End PBXGroup section */ /* Begin PBXNativeTarget section */ @@ -216,9 +203,12 @@ isa = PBXNativeTarget; buildConfigurationList = 99BCDCCD18008C0000B8E66B /* Build configuration list for PBXNativeTarget "TableViewCellWithAutoLayout" */; buildPhases = ( + FE8D2EDAD3B843D5ABF88A67 /* Check Pods Manifest.lock */, 99BCDC9D18008C0000B8E66B /* Sources */, 99BCDC9E18008C0000B8E66B /* Frameworks */, 99BCDC9F18008C0000B8E66B /* Resources */, + 5737466CF2C0FC46426305CF /* Embed Pods Frameworks */, + 4306B9C3FDF52317D88B94F0 /* Copy Pods Resources */, ); buildRules = ( ); @@ -302,6 +292,54 @@ }; /* End PBXResourcesBuildPhase section */ +/* Begin PBXShellScriptBuildPhase section */ + 4306B9C3FDF52317D88B94F0 /* Copy Pods Resources */ = { + isa = PBXShellScriptBuildPhase; + buildActionMask = 2147483647; + files = ( + ); + inputPaths = ( + ); + name = "Copy Pods Resources"; + outputPaths = ( + ); + runOnlyForDeploymentPostprocessing = 0; + shellPath = /bin/sh; + shellScript = "\"${SRCROOT}/Pods/Target Support Files/Pods/Pods-resources.sh\"\n"; + showEnvVarsInLog = 0; + }; + 5737466CF2C0FC46426305CF /* Embed Pods Frameworks */ = { + isa = PBXShellScriptBuildPhase; + buildActionMask = 2147483647; + files = ( + ); + inputPaths = ( + ); + name = "Embed Pods Frameworks"; + outputPaths = ( + ); + runOnlyForDeploymentPostprocessing = 0; + shellPath = /bin/sh; + shellScript = "\"${SRCROOT}/Pods/Target Support Files/Pods/Pods-frameworks.sh\"\n"; + showEnvVarsInLog = 0; + }; + FE8D2EDAD3B843D5ABF88A67 /* Check Pods Manifest.lock */ = { + isa = PBXShellScriptBuildPhase; + buildActionMask = 2147483647; + files = ( + ); + inputPaths = ( + ); + name = "Check Pods Manifest.lock"; + outputPaths = ( + ); + runOnlyForDeploymentPostprocessing = 0; + shellPath = /bin/sh; + shellScript = "diff \"${PODS_ROOT}/../Podfile.lock\" \"${PODS_ROOT}/Manifest.lock\" > /dev/null\nif [[ $? != 0 ]] ; then\n cat << EOM\nerror: The sandbox is not in sync with the Podfile.lock. Run 'pod install' or update your CocoaPods installation.\nEOM\n exit 1\nfi\n"; + showEnvVarsInLog = 0; + }; +/* End PBXShellScriptBuildPhase section */ + /* Begin PBXSourcesBuildPhase section */ 99BCDC9D18008C0000B8E66B /* Sources */ = { isa = PBXSourcesBuildPhase; @@ -309,9 +347,6 @@ files = ( 5A3B25361945F89500838EF4 /* NibTableViewCell.swift in Sources */, A7F5DDAE194417DC008E238B /* TableViewController.swift in Sources */, - B126BA121959EF4E0018DBAE /* ALView+PureLayout.m in Sources */, - B126BA131959EF4E0018DBAE /* NSArray+PureLayout.m in Sources */, - B126BA141959EF4E0018DBAE /* NSLayoutConstraint+PureLayout.m in Sources */, A7F5DDAA194408D9008E238B /* AppDelegate.swift in Sources */, A7F5DDAC19440B7B008E238B /* Model.swift in Sources */, A7C103221943F73D006A9720 /* TableViewCell.swift in Sources */, @@ -431,6 +466,7 @@ }; 99BCDCCE18008C0000B8E66B /* Debug */ = { isa = XCBuildConfiguration; + baseConfigurationReference = 57612988E552EA49095C8330 /* Pods.debug.xcconfig */; buildSettings = { ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; ASSETCATALOG_COMPILER_LAUNCHIMAGE_NAME = LaunchImage; @@ -450,6 +486,7 @@ }; 99BCDCCF18008C0000B8E66B /* Release */ = { isa = XCBuildConfiguration; + baseConfigurationReference = E8389E598E67F5F16660D9AC /* Pods.release.xcconfig */; buildSettings = { ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; ASSETCATALOG_COMPILER_LAUNCHIMAGE_NAME = LaunchImage; diff --git a/TableViewCellWithAutoLayout/PureLayout/NSArray+PureLayout.h b/TableViewCellWithAutoLayout/PureLayout/NSArray+PureLayout.h deleted file mode 100755 index 10ece57..0000000 --- a/TableViewCellWithAutoLayout/PureLayout/NSArray+PureLayout.h +++ /dev/null @@ -1,107 +0,0 @@ -// -// NSArray+PureLayout.h -// v2.0.5 -// https://github.com/smileyborg/PureLayout -// -// Copyright (c) 2012 Richard Turton -// Copyright (c) 2013-2015 Tyler Fox -// -// This code is distributed under the terms and conditions of the MIT license. -// -// Permission is hereby granted, free of charge, to any person obtaining a copy -// of this software and associated documentation files (the "Software"), to -// deal in the Software without restriction, including without limitation the -// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or -// sell copies of the Software, and to permit persons to whom the Software is -// furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included in -// all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING -// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS -// IN THE SOFTWARE. -// - -#import "PureLayoutDefines.h" - - -#pragma mark - NSArray+PureLayout - -/** - A category on NSArray that provides a simple yet powerful interface to: - - Manage an array of Auto Layout constraints - - Apply constraints to an array of views - */ -@interface NSArray (PureLayout) - - -#pragma mark Array of Constraints - -/** Activates the constraints in this array. */ -- (void)autoInstallConstraints; - -/** Deactivates the constraints in this array. */ -- (void)autoRemoveConstraints; - -#if __PureLayout_MinBaseSDK_iOS_8_0 - -/** Sets the string as the identifier for the constraints in this array. Available in iOS 7.0 and OS X 10.9 and later. */ -- (instancetype)autoIdentifyConstraints:(NSString *)identifier; - -#endif /* __PureLayout_MinBaseSDK_iOS_8_0 */ - - -#pragma mark Array of Views - -/** Aligns views in this array to one another along a given edge. */ -- (NSArray *)autoAlignViewsToEdge:(ALEdge)edge; - -/** Aligns views in this array to one another along a given axis. */ -- (NSArray *)autoAlignViewsToAxis:(ALAxis)axis; - -/** Matches a given dimension of all the views in this array. */ -- (NSArray *)autoMatchViewsDimension:(ALDimension)dimension; - -/** Sets the given dimension of all the views in this array to a given size. */ -- (NSArray *)autoSetViewsDimension:(ALDimension)dimension toSize:(CGFloat)size; - -/** Sets all of the views in this array to a given size. */ -- (NSArray *)autoSetViewsDimensionsToSize:(CGSize)size; - - -/** Distributes the views in this array equally along the selected axis in their superview. Views will be the same size (variable) in the dimension along the axis and will have spacing (fixed) between them. */ -- (NSArray *)autoDistributeViewsAlongAxis:(ALAxis)axis - alignedTo:(ALAttribute)alignment - withFixedSpacing:(CGFloat)spacing; - -/** Distributes the views in this array equally along the selected axis in their superview. Views will be the same size (variable) in the dimension along the axis and will have spacing (fixed) between them, with optional insets from the first and last views to their superview. */ -- (NSArray *)autoDistributeViewsAlongAxis:(ALAxis)axis - alignedTo:(ALAttribute)alignment - withFixedSpacing:(CGFloat)spacing - insetSpacing:(BOOL)shouldSpaceInsets; - -/** Distributes the views in this array equally along the selected axis in their superview. Views will have spacing (fixed) between them, with optional insets from the first and last views to their superview, and optionally constrained to the same size in the dimension along the axis. */ -- (NSArray *)autoDistributeViewsAlongAxis:(ALAxis)axis - alignedTo:(ALAttribute)alignment - withFixedSpacing:(CGFloat)spacing - insetSpacing:(BOOL)shouldSpaceInsets - matchedSizes:(BOOL)shouldMatchSizes; - - -/** Distributes the views in this array equally along the selected axis in their superview. Views will be the same size (fixed) in the dimension along the axis and will have spacing (variable) between them. */ -- (NSArray *)autoDistributeViewsAlongAxis:(ALAxis)axis - alignedTo:(ALAttribute)alignment - withFixedSize:(CGFloat)size; - -/** Distributes the views in this array equally along the selected axis in their superview. Views will be the same size (fixed) in the dimension along the axis and will have spacing (variable) between them, with optional insets from the first and last views to their superview. */ -- (NSArray *)autoDistributeViewsAlongAxis:(ALAxis)axis - alignedTo:(ALAttribute)alignment - withFixedSize:(CGFloat)size - insetSpacing:(BOOL)shouldSpaceInsets; - -@end diff --git a/TableViewCellWithAutoLayout/PureLayout/NSLayoutConstraint+PureLayout.m b/TableViewCellWithAutoLayout/PureLayout/NSLayoutConstraint+PureLayout.m deleted file mode 100755 index 1a290b5..0000000 --- a/TableViewCellWithAutoLayout/PureLayout/NSLayoutConstraint+PureLayout.m +++ /dev/null @@ -1,314 +0,0 @@ -// -// NSLayoutConstraint+PureLayout.m -// v2.0.5 -// https://github.com/smileyborg/PureLayout -// -// Copyright (c) 2013-2015 Tyler Fox -// -// This code is distributed under the terms and conditions of the MIT license. -// -// Permission is hereby granted, free of charge, to any person obtaining a copy -// of this software and associated documentation files (the "Software"), to -// deal in the Software without restriction, including without limitation the -// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or -// sell copies of the Software, and to permit persons to whom the Software is -// furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included in -// all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING -// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS -// IN THE SOFTWARE. -// - -#import "NSLayoutConstraint+PureLayout.h" -#import "ALView+PureLayout.h" -#import "PureLayout+Internal.h" - - -#pragma mark - NSLayoutConstraint+PureLayout - -@implementation NSLayoutConstraint (PureLayout) - - -#pragma mark Installing & Removing Constraints - -/** - Activates the constraint. - */ -- (void)autoInstall -{ -#if __PureLayout_MinBaseSDK_iOS_8_0 || __PureLayout_MinBaseSDK_OSX_10_10 - if ([self respondsToSelector:@selector(setActive:)]) { - [ALView al_applyGlobalStateToConstraint:self]; - if ([ALView al_preventAutomaticConstraintInstallation]) { - [[ALView al_currentArrayOfCreatedConstraints] addObject:self]; - } else { - self.active = YES; - } - return; - } -#endif /* __PureLayout_MinBaseSDK_iOS_8_0 || __PureLayout_MinBaseSDK_OSX_10_10 */ - - NSAssert(self.firstItem || self.secondItem, @"Can't install a constraint with nil firstItem and secondItem."); - if (self.firstItem) { - if (self.secondItem) { - NSAssert([self.firstItem isKindOfClass:[ALView class]] && [self.secondItem isKindOfClass:[ALView class]], @"Can only automatically install a constraint if both items are views."); - ALView *commonSuperview = [self.firstItem al_commonSuperviewWithView:self.secondItem]; - [commonSuperview al_addConstraint:self]; - } else { - NSAssert([self.firstItem isKindOfClass:[ALView class]], @"Can only automatically install a constraint if the item is a view."); - [self.firstItem al_addConstraint:self]; - } - } else { - NSAssert([self.secondItem isKindOfClass:[ALView class]], @"Can only automatically install a constraint if the item is a view."); - [self.secondItem al_addConstraint:self]; - } -} - -/** - Deactivates the constraint. - */ -- (void)autoRemove -{ -#if __PureLayout_MinBaseSDK_iOS_8_0 || __PureLayout_MinBaseSDK_OSX_10_10 - if ([self respondsToSelector:@selector(setActive:)]) { - self.active = NO; - return; - } -#endif /* __PureLayout_MinBaseSDK_iOS_8_0 || __PureLayout_MinBaseSDK_OSX_10_10 */ - - if (self.secondItem) { - ALView *commonSuperview = [self.firstItem al_commonSuperviewWithView:self.secondItem]; - while (commonSuperview) { - if ([commonSuperview.constraints containsObject:self]) { - [commonSuperview removeConstraint:self]; - return; - } - commonSuperview = commonSuperview.superview; - } - } - else { - [self.firstItem removeConstraint:self]; - return; - } - NSAssert(nil, @"Failed to remove constraint: %@", self); -} - - -#pragma mark Identify Constraints - -#if __PureLayout_MinBaseSDK_iOS_8_0 || __PureLayout_MinBaseSDK_OSX_10_10 - -/** - Sets the string as the identifier for this constraint. Available in iOS 7.0 and OS X 10.9 and later. - The identifier will be printed along with the constraint's description. - This is helpful to document a constraint's purpose and aid in debugging. - - @param identifier A string used to identify this constraint. - @return This constraint. - */ -- (instancetype)autoIdentify:(NSString *)identifier -{ - if ([self respondsToSelector:@selector(setIdentifier:)]) { - self.identifier = identifier; - } - return self; -} - -#endif /* __PureLayout_MinBaseSDK_iOS_8_0 || __PureLayout_MinBaseSDK_OSX_10_10 */ - - -#pragma mark Internal Methods - -/** - Returns the corresponding NSLayoutAttribute for the given ALAttribute. - - @return The layout attribute for the given ALAttribute. - */ -+ (NSLayoutAttribute)al_layoutAttributeForAttribute:(ALAttribute)attribute -{ - NSLayoutAttribute layoutAttribute = NSLayoutAttributeNotAnAttribute; - switch (attribute) { - case ALEdgeLeft: - layoutAttribute = NSLayoutAttributeLeft; - break; - case ALEdgeRight: - layoutAttribute = NSLayoutAttributeRight; - break; - case ALEdgeTop: - layoutAttribute = NSLayoutAttributeTop; - break; - case ALEdgeBottom: - layoutAttribute = NSLayoutAttributeBottom; - break; - case ALEdgeLeading: - layoutAttribute = NSLayoutAttributeLeading; - break; - case ALEdgeTrailing: - layoutAttribute = NSLayoutAttributeTrailing; - break; - case ALDimensionWidth: - layoutAttribute = NSLayoutAttributeWidth; - break; - case ALDimensionHeight: - layoutAttribute = NSLayoutAttributeHeight; - break; - case ALAxisVertical: - layoutAttribute = NSLayoutAttributeCenterX; - break; - case ALAxisHorizontal: - layoutAttribute = NSLayoutAttributeCenterY; - break; - case ALAxisBaseline: // same value as ALAxisLastBaseline - layoutAttribute = NSLayoutAttributeBaseline; - break; -#if __PureLayout_MinBaseSDK_iOS_8_0 - case ALAxisFirstBaseline: - NSAssert(__PureLayout_MinSysVer_iOS_8_0, @"ALAxisFirstBaseline is only supported on iOS 8.0 or higher."); - layoutAttribute = NSLayoutAttributeFirstBaseline; - break; - case ALMarginLeft: - NSAssert(__PureLayout_MinSysVer_iOS_8_0, @"ALEdgeLeftMargin is only supported on iOS 8.0 or higher."); - layoutAttribute = NSLayoutAttributeLeftMargin; - break; - case ALMarginRight: - NSAssert(__PureLayout_MinSysVer_iOS_8_0, @"ALEdgeRightMargin is only supported on iOS 8.0 or higher."); - layoutAttribute = NSLayoutAttributeRightMargin; - break; - case ALMarginTop: - NSAssert(__PureLayout_MinSysVer_iOS_8_0, @"ALEdgeTopMargin is only supported on iOS 8.0 or higher."); - layoutAttribute = NSLayoutAttributeTopMargin; - break; - case ALMarginBottom: - NSAssert(__PureLayout_MinSysVer_iOS_8_0, @"ALEdgeBottomMargin is only supported on iOS 8.0 or higher."); - layoutAttribute = NSLayoutAttributeBottomMargin; - break; - case ALMarginLeading: - NSAssert(__PureLayout_MinSysVer_iOS_8_0, @"ALEdgeLeadingMargin is only supported on iOS 8.0 or higher."); - layoutAttribute = NSLayoutAttributeLeadingMargin; - break; - case ALMarginTrailing: - NSAssert(__PureLayout_MinSysVer_iOS_8_0, @"ALEdgeTrailingMargin is only supported on iOS 8.0 or higher."); - layoutAttribute = NSLayoutAttributeTrailingMargin; - break; - case ALMarginAxisVertical: - NSAssert(__PureLayout_MinSysVer_iOS_8_0, @"ALAxisVerticalMargin is only supported on iOS 8.0 or higher."); - layoutAttribute = NSLayoutAttributeCenterXWithinMargins; - break; - case ALMarginAxisHorizontal: - NSAssert(__PureLayout_MinSysVer_iOS_8_0, @"ALAxisHorizontalMargin is only supported on iOS 8.0 or higher."); - layoutAttribute = NSLayoutAttributeCenterYWithinMargins; - break; -#endif /* __PureLayout_MinBaseSDK_iOS_8_0 */ - default: - NSAssert(nil, @"Not a valid ALAttribute."); - break; - } - return layoutAttribute; -} - -/** - Returns the corresponding ALLayoutConstraintAxis for the given ALAxis. - - @return The constraint axis for the given axis. - */ -+ (ALLayoutConstraintAxis)al_constraintAxisForAxis:(ALAxis)axis -{ - ALLayoutConstraintAxis constraintAxis; - switch (axis) { - case ALAxisVertical: - constraintAxis = ALLayoutConstraintAxisVertical; - break; - case ALAxisHorizontal: - case ALAxisBaseline: // same value as ALAxisLastBaseline -#if __PureLayout_MinBaseSDK_iOS_8_0 - case ALAxisFirstBaseline: -#endif /* __PureLayout_MinBaseSDK_iOS_8_0 */ - constraintAxis = ALLayoutConstraintAxisHorizontal; - break; - default: - NSAssert(nil, @"Not a valid ALAxis."); - constraintAxis = ALLayoutConstraintAxisHorizontal; // default to a random value to satisfy the compiler - break; - } - return constraintAxis; -} - -#if __PureLayout_MinBaseSDK_iOS_8_0 - -/** - Returns the corresponding margin for the given edge. - - @param edge The edge to convert to the corresponding margin. - @return The margin for the given edge. - */ -+ (ALMargin)al_marginForEdge:(ALEdge)edge -{ - NSAssert(__PureLayout_MinSysVer_iOS_8_0, @"Margin attributes are only supported on iOS 8.0 or higher."); - ALMargin margin; - switch (edge) { - case ALEdgeLeft: - margin = ALMarginLeft; - break; - case ALEdgeRight: - margin = ALMarginRight; - break; - case ALEdgeTop: - margin = ALMarginTop; - break; - case ALEdgeBottom: - margin = ALMarginBottom; - break; - case ALEdgeLeading: - margin = ALMarginLeading; - break; - case ALEdgeTrailing: - margin = ALMarginTrailing; - break; - default: - NSAssert(nil, @"Not a valid ALEdge."); - margin = ALMarginLeft; // default to a random value to satisfy the compiler - break; - } - return margin; -} - -/** - Returns the corresponding margin axis for the given axis. - - @param axis The axis to convert to the corresponding margin axis. - @return The margin axis for the given axis. - */ -+ (ALMarginAxis)al_marginAxisForAxis:(ALAxis)axis -{ - NSAssert(__PureLayout_MinSysVer_iOS_8_0, @"Margin attributes are only supported on iOS 8.0 or higher."); - ALMarginAxis marginAxis; - switch (axis) { - case ALAxisVertical: - marginAxis = ALMarginAxisVertical; - break; - case ALAxisHorizontal: - marginAxis = ALMarginAxisHorizontal; - break; - case ALAxisBaseline: - case ALAxisFirstBaseline: - NSAssert(nil, @"The baseline axis attributes do not have corresponding margin axis attributes."); - marginAxis = ALMarginAxisVertical; // default to a random value to satisfy the compiler - break; - default: - NSAssert(nil, @"Not a valid ALAxis."); - marginAxis = ALMarginAxisVertical; // default to a random value to satisfy the compiler - break; - } - return marginAxis; -} - -#endif /* __PureLayout_MinBaseSDK_iOS_8_0 */ - -@end diff --git a/TableViewCellWithAutoLayout/TableViewController/Model.swift b/TableViewCellWithAutoLayout/TableViewController/Model.swift index 9acaf97..b7c47d3 100644 --- a/TableViewCellWithAutoLayout/TableViewController/Model.swift +++ b/TableViewCellWithAutoLayout/TableViewController/Model.swift @@ -5,7 +5,7 @@ // Copyright (c) 2014 Tyler Fox // -import Foundation +import UIKit class Model { diff --git a/TableViewCellWithAutoLayout/TableViewController/TableViewCell.swift b/TableViewCellWithAutoLayout/TableViewController/TableViewCell.swift index 3cf35ef..c8a9c54 100644 --- a/TableViewCellWithAutoLayout/TableViewController/TableViewCell.swift +++ b/TableViewCellWithAutoLayout/TableViewController/TableViewCell.swift @@ -6,6 +6,7 @@ // import UIKit +import PureLayout class TableViewCell: UITableViewCell { @@ -64,7 +65,7 @@ class TableViewCell: UITableViewCell // contentView.bounds = CGRect(x: 0.0, y: 0.0, width: 99999.0, height: 99999.0) // Prevent the two UILabels from being compressed below their intrinsic content height - UIView.autoSetPriority(UILayoutPriorityRequired) { + NSLayoutConstraint.autoSetPriority(UILayoutPriorityRequired) { self.titleLabel.autoSetContentCompressionResistancePriorityForAxis(.Vertical) self.bodyLabel.autoSetContentCompressionResistancePriorityForAxis(.Vertical) } diff --git a/TableViewCellWithAutoLayout/TableViewController/TableViewCellWithAutoLayout-Bridging-Header.h b/TableViewCellWithAutoLayout/TableViewController/TableViewCellWithAutoLayout-Bridging-Header.h index 5e95681..e11d920 100644 --- a/TableViewCellWithAutoLayout/TableViewController/TableViewCellWithAutoLayout-Bridging-Header.h +++ b/TableViewCellWithAutoLayout/TableViewController/TableViewCellWithAutoLayout-Bridging-Header.h @@ -1,5 +1,3 @@ // // Use this file to import your target's public headers that you would like to expose to Swift. // - -#import "PureLayout.h" From 1988946fe98df148794907b90932f4c0487df990 Mon Sep 17 00:00:00 2001 From: Tyler Fox Date: Sun, 16 Aug 2015 23:13:10 -0700 Subject: [PATCH 28/30] Add note about Swift 2.0 --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index a2c434f..60f865d 100644 --- a/README.md +++ b/README.md @@ -7,7 +7,7 @@ Sample project demonstrating self-sizing table view cells in iOS 8, using Auto L There are two branches in this repository: -1. **master** (this branch) - A Swift implementation +1. **master** (this branch) - A Swift 2.0 implementation 2. **[objective-c](https://github.com/smileyborg/TableViewCellWithAutoLayoutiOS8/tree/objective-c)** - An Objective-C implementation To build & run the app, you should open the `TableViewCellWithAutoLayout.xcworkspace` in Xcode. From 448a38ad3ed053f155aefe54094d536c1f5826fa Mon Sep 17 00:00:00 2001 From: Tyler Fox Date: Sat, 3 Oct 2015 21:08:18 -0700 Subject: [PATCH 29/30] Update .gitignore, check in .xcworkspace The original .gitignore was outdated, and was preventing the workspace from being added to the repo. --- .gitignore | 37 ++++++++++++++++--- .../contents.xcworkspacedata | 10 +++++ 2 files changed, 41 insertions(+), 6 deletions(-) create mode 100644 TableViewCellWithAutoLayout.xcworkspace/contents.xcworkspacedata diff --git a/.gitignore b/.gitignore index 89c499e..04529e0 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,12 @@ # Xcode -.DS_Store +# +# gitignore contributors: remember to update Global/Xcode.gitignore, Objective-C.gitignore & Swift.gitignore + +## Build generated build/ +DerivedData + +## Various settings *.pbxuser !default.pbxuser *.mode1v3 @@ -9,10 +15,29 @@ build/ !default.mode2v3 *.perspectivev3 !default.perspectivev3 -*.xcworkspace -!default.xcworkspace xcuserdata -profile + +## Other +*.xccheckout *.moved-aside -DerivedData -.idea/ +*.xcuserstate +*.xcscmblueprint + +## Obj-C/Swift specific +*.hmap +*.ipa + +# CocoaPods +# +# We recommend against adding the Pods directory to your .gitignore. However +# you should judge for yourself, the pros and cons are mentioned at: +# http://guides.cocoapods.org/using/using-cocoapods.html#should-i-check-the-pods-directory-into-source-control +# +#Pods/ + +# Carthage +# +# Add this line if you want to avoid checking in source code from Carthage dependencies. +# Carthage/Checkouts + +Carthage/Build \ No newline at end of file diff --git a/TableViewCellWithAutoLayout.xcworkspace/contents.xcworkspacedata b/TableViewCellWithAutoLayout.xcworkspace/contents.xcworkspacedata new file mode 100644 index 0000000..8ff91bb --- /dev/null +++ b/TableViewCellWithAutoLayout.xcworkspace/contents.xcworkspacedata @@ -0,0 +1,10 @@ + + + + + + + From 061afd6ab8c07d15d7731c4d6f9243f418fb21c9 Mon Sep 17 00:00:00 2001 From: chenglin Date: Sat, 14 May 2016 23:15:05 -0400 Subject: [PATCH 30/30] Fix Xcode 7.3 selector error and swift warnings --- .../TableViewController/TableViewController.swift | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/TableViewCellWithAutoLayout/TableViewController/TableViewController.swift b/TableViewCellWithAutoLayout/TableViewController/TableViewController.swift index 9a3c47a..69de322 100644 --- a/TableViewCellWithAutoLayout/TableViewController/TableViewController.swift +++ b/TableViewCellWithAutoLayout/TableViewController/TableViewController.swift @@ -18,8 +18,8 @@ class TableViewController: UITableViewController super.viewDidLoad() title = "iOS 8 Self Sizing Cells" - navigationItem.leftBarButtonItem = UIBarButtonItem(barButtonSystemItem: UIBarButtonSystemItem.Trash, target: self, action: "clear") - navigationItem.rightBarButtonItem = UIBarButtonItem(barButtonSystemItem: UIBarButtonSystemItem.Add, target: self, action: "addRow") + navigationItem.leftBarButtonItem = UIBarButtonItem(barButtonSystemItem: UIBarButtonSystemItem.Trash, target: self, action: #selector(TableViewController.clear)) + navigationItem.rightBarButtonItem = UIBarButtonItem(barButtonSystemItem: UIBarButtonSystemItem.Add, target: self, action: #selector(TableViewController.addRow)) tableView.allowsSelection = false @@ -49,7 +49,7 @@ class TableViewController: UITableViewController { super.viewDidAppear(animated) - NSNotificationCenter.defaultCenter().addObserver(self, selector: "contentSizeCategoryChanged:", name: UIContentSizeCategoryDidChangeNotification, object: nil) + NSNotificationCenter.defaultCenter().addObserver(self, selector: #selector(TableViewController.contentSizeCategoryChanged(_:)), name: UIContentSizeCategoryDidChangeNotification, object: nil) } override func viewDidDisappear(animated: Bool) @@ -69,7 +69,7 @@ class TableViewController: UITableViewController func clear() { var rowsToDelete: [NSIndexPath] = [] - for (var i = 0; i < model.dataArray.count; i++) { + for i in 0..