├── CollectionViewAutoSizingTest.xcodeproj ├── project.pbxproj ├── project.xcworkspace │ └── contents.xcworkspacedata └── xcuserdata │ └── sun.xcuserdatad │ └── xcschemes │ ├── CollectionViewAutoSizingTest.xcscheme │ └── xcschememanagement.plist └── CollectionViewAutoSizingTest ├── AppDelegate.swift ├── Assets.xcassets └── AppIcon.appiconset │ └── Contents.json ├── Base.lproj ├── LaunchScreen.storyboard └── Main.storyboard ├── Cell.swift ├── Cell.xib ├── Info.plist └── ViewController.swift /CollectionViewAutoSizingTest.xcodeproj/project.pbxproj: -------------------------------------------------------------------------------- 1 | // !$*UTF8*$! 2 | { 3 | archiveVersion = 1; 4 | classes = { 5 | }; 6 | objectVersion = 46; 7 | objects = { 8 | 9 | /* Begin PBXBuildFile section */ 10 | A47B7AA61E38544800DAD9C7 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = A47B7AA51E38544800DAD9C7 /* AppDelegate.swift */; }; 11 | A47B7AA81E38544800DAD9C7 /* ViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = A47B7AA71E38544800DAD9C7 /* ViewController.swift */; }; 12 | A47B7AAB1E38544800DAD9C7 /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = A47B7AA91E38544800DAD9C7 /* Main.storyboard */; }; 13 | A47B7AAD1E38544800DAD9C7 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = A47B7AAC1E38544800DAD9C7 /* Assets.xcassets */; }; 14 | A47B7AB01E38544800DAD9C7 /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = A47B7AAE1E38544800DAD9C7 /* LaunchScreen.storyboard */; }; 15 | A47B7AB91E385F2A00DAD9C7 /* Cell.swift in Sources */ = {isa = PBXBuildFile; fileRef = A47B7AB71E385F2A00DAD9C7 /* Cell.swift */; }; 16 | A47B7ABA1E385F2A00DAD9C7 /* Cell.xib in Resources */ = {isa = PBXBuildFile; fileRef = A47B7AB81E385F2A00DAD9C7 /* Cell.xib */; }; 17 | /* End PBXBuildFile section */ 18 | 19 | /* Begin PBXFileReference section */ 20 | A47B7AA21E38544800DAD9C7 /* CollectionViewAutoSizingTest.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = CollectionViewAutoSizingTest.app; sourceTree = BUILT_PRODUCTS_DIR; }; 21 | A47B7AA51E38544800DAD9C7 /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = ""; }; 22 | A47B7AA71E38544800DAD9C7 /* ViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ViewController.swift; sourceTree = ""; }; 23 | A47B7AAA1E38544800DAD9C7 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/Main.storyboard; sourceTree = ""; }; 24 | A47B7AAC1E38544800DAD9C7 /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = ""; }; 25 | A47B7AAF1E38544800DAD9C7 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/LaunchScreen.storyboard; sourceTree = ""; }; 26 | A47B7AB11E38544800DAD9C7 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 27 | A47B7AB71E385F2A00DAD9C7 /* Cell.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Cell.swift; sourceTree = ""; }; 28 | A47B7AB81E385F2A00DAD9C7 /* Cell.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; path = Cell.xib; sourceTree = ""; }; 29 | /* End PBXFileReference section */ 30 | 31 | /* Begin PBXFrameworksBuildPhase section */ 32 | A47B7A9F1E38544800DAD9C7 /* Frameworks */ = { 33 | isa = PBXFrameworksBuildPhase; 34 | buildActionMask = 2147483647; 35 | files = ( 36 | ); 37 | runOnlyForDeploymentPostprocessing = 0; 38 | }; 39 | /* End PBXFrameworksBuildPhase section */ 40 | 41 | /* Begin PBXGroup section */ 42 | A47B7A991E38544800DAD9C7 = { 43 | isa = PBXGroup; 44 | children = ( 45 | A47B7AA41E38544800DAD9C7 /* CollectionViewAutoSizingTest */, 46 | A47B7AA31E38544800DAD9C7 /* Products */, 47 | ); 48 | sourceTree = ""; 49 | }; 50 | A47B7AA31E38544800DAD9C7 /* Products */ = { 51 | isa = PBXGroup; 52 | children = ( 53 | A47B7AA21E38544800DAD9C7 /* CollectionViewAutoSizingTest.app */, 54 | ); 55 | name = Products; 56 | sourceTree = ""; 57 | }; 58 | A47B7AA41E38544800DAD9C7 /* CollectionViewAutoSizingTest */ = { 59 | isa = PBXGroup; 60 | children = ( 61 | A47B7AA51E38544800DAD9C7 /* AppDelegate.swift */, 62 | A47B7AA71E38544800DAD9C7 /* ViewController.swift */, 63 | A47B7AA91E38544800DAD9C7 /* Main.storyboard */, 64 | A47B7AAC1E38544800DAD9C7 /* Assets.xcassets */, 65 | A47B7AAE1E38544800DAD9C7 /* LaunchScreen.storyboard */, 66 | A47B7AB11E38544800DAD9C7 /* Info.plist */, 67 | A47B7AB71E385F2A00DAD9C7 /* Cell.swift */, 68 | A47B7AB81E385F2A00DAD9C7 /* Cell.xib */, 69 | ); 70 | path = CollectionViewAutoSizingTest; 71 | sourceTree = ""; 72 | }; 73 | /* End PBXGroup section */ 74 | 75 | /* Begin PBXNativeTarget section */ 76 | A47B7AA11E38544800DAD9C7 /* CollectionViewAutoSizingTest */ = { 77 | isa = PBXNativeTarget; 78 | buildConfigurationList = A47B7AB41E38544800DAD9C7 /* Build configuration list for PBXNativeTarget "CollectionViewAutoSizingTest" */; 79 | buildPhases = ( 80 | A47B7A9E1E38544800DAD9C7 /* Sources */, 81 | A47B7A9F1E38544800DAD9C7 /* Frameworks */, 82 | A47B7AA01E38544800DAD9C7 /* Resources */, 83 | ); 84 | buildRules = ( 85 | ); 86 | dependencies = ( 87 | ); 88 | name = CollectionViewAutoSizingTest; 89 | productName = CollectionViewAutoSizingTest; 90 | productReference = A47B7AA21E38544800DAD9C7 /* CollectionViewAutoSizingTest.app */; 91 | productType = "com.apple.product-type.application"; 92 | }; 93 | /* End PBXNativeTarget section */ 94 | 95 | /* Begin PBXProject section */ 96 | A47B7A9A1E38544800DAD9C7 /* Project object */ = { 97 | isa = PBXProject; 98 | attributes = { 99 | LastSwiftUpdateCheck = 0820; 100 | LastUpgradeCheck = 0820; 101 | ORGANIZATIONNAME = "Wasin Wiwongsak"; 102 | TargetAttributes = { 103 | A47B7AA11E38544800DAD9C7 = { 104 | CreatedOnToolsVersion = 8.2.1; 105 | DevelopmentTeam = 8NQ7AXAYPG; 106 | ProvisioningStyle = Automatic; 107 | }; 108 | }; 109 | }; 110 | buildConfigurationList = A47B7A9D1E38544800DAD9C7 /* Build configuration list for PBXProject "CollectionViewAutoSizingTest" */; 111 | compatibilityVersion = "Xcode 3.2"; 112 | developmentRegion = English; 113 | hasScannedForEncodings = 0; 114 | knownRegions = ( 115 | en, 116 | Base, 117 | ); 118 | mainGroup = A47B7A991E38544800DAD9C7; 119 | productRefGroup = A47B7AA31E38544800DAD9C7 /* Products */; 120 | projectDirPath = ""; 121 | projectRoot = ""; 122 | targets = ( 123 | A47B7AA11E38544800DAD9C7 /* CollectionViewAutoSizingTest */, 124 | ); 125 | }; 126 | /* End PBXProject section */ 127 | 128 | /* Begin PBXResourcesBuildPhase section */ 129 | A47B7AA01E38544800DAD9C7 /* Resources */ = { 130 | isa = PBXResourcesBuildPhase; 131 | buildActionMask = 2147483647; 132 | files = ( 133 | A47B7AB01E38544800DAD9C7 /* LaunchScreen.storyboard in Resources */, 134 | A47B7ABA1E385F2A00DAD9C7 /* Cell.xib in Resources */, 135 | A47B7AAD1E38544800DAD9C7 /* Assets.xcassets in Resources */, 136 | A47B7AAB1E38544800DAD9C7 /* Main.storyboard in Resources */, 137 | ); 138 | runOnlyForDeploymentPostprocessing = 0; 139 | }; 140 | /* End PBXResourcesBuildPhase section */ 141 | 142 | /* Begin PBXSourcesBuildPhase section */ 143 | A47B7A9E1E38544800DAD9C7 /* Sources */ = { 144 | isa = PBXSourcesBuildPhase; 145 | buildActionMask = 2147483647; 146 | files = ( 147 | A47B7AA81E38544800DAD9C7 /* ViewController.swift in Sources */, 148 | A47B7AA61E38544800DAD9C7 /* AppDelegate.swift in Sources */, 149 | A47B7AB91E385F2A00DAD9C7 /* Cell.swift in Sources */, 150 | ); 151 | runOnlyForDeploymentPostprocessing = 0; 152 | }; 153 | /* End PBXSourcesBuildPhase section */ 154 | 155 | /* Begin PBXVariantGroup section */ 156 | A47B7AA91E38544800DAD9C7 /* Main.storyboard */ = { 157 | isa = PBXVariantGroup; 158 | children = ( 159 | A47B7AAA1E38544800DAD9C7 /* Base */, 160 | ); 161 | name = Main.storyboard; 162 | sourceTree = ""; 163 | }; 164 | A47B7AAE1E38544800DAD9C7 /* LaunchScreen.storyboard */ = { 165 | isa = PBXVariantGroup; 166 | children = ( 167 | A47B7AAF1E38544800DAD9C7 /* Base */, 168 | ); 169 | name = LaunchScreen.storyboard; 170 | sourceTree = ""; 171 | }; 172 | /* End PBXVariantGroup section */ 173 | 174 | /* Begin XCBuildConfiguration section */ 175 | A47B7AB21E38544800DAD9C7 /* Debug */ = { 176 | isa = XCBuildConfiguration; 177 | buildSettings = { 178 | ALWAYS_SEARCH_USER_PATHS = NO; 179 | CLANG_ANALYZER_NONNULL = YES; 180 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; 181 | CLANG_CXX_LIBRARY = "libc++"; 182 | CLANG_ENABLE_MODULES = YES; 183 | CLANG_ENABLE_OBJC_ARC = YES; 184 | CLANG_WARN_BOOL_CONVERSION = YES; 185 | CLANG_WARN_CONSTANT_CONVERSION = YES; 186 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 187 | CLANG_WARN_DOCUMENTATION_COMMENTS = YES; 188 | CLANG_WARN_EMPTY_BODY = YES; 189 | CLANG_WARN_ENUM_CONVERSION = YES; 190 | CLANG_WARN_INFINITE_RECURSION = YES; 191 | CLANG_WARN_INT_CONVERSION = YES; 192 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 193 | CLANG_WARN_SUSPICIOUS_MOVE = YES; 194 | CLANG_WARN_UNREACHABLE_CODE = YES; 195 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 196 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; 197 | COPY_PHASE_STRIP = NO; 198 | DEBUG_INFORMATION_FORMAT = dwarf; 199 | ENABLE_STRICT_OBJC_MSGSEND = YES; 200 | ENABLE_TESTABILITY = YES; 201 | GCC_C_LANGUAGE_STANDARD = gnu99; 202 | GCC_DYNAMIC_NO_PIC = NO; 203 | GCC_NO_COMMON_BLOCKS = YES; 204 | GCC_OPTIMIZATION_LEVEL = 0; 205 | GCC_PREPROCESSOR_DEFINITIONS = ( 206 | "DEBUG=1", 207 | "$(inherited)", 208 | ); 209 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 210 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 211 | GCC_WARN_UNDECLARED_SELECTOR = YES; 212 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 213 | GCC_WARN_UNUSED_FUNCTION = YES; 214 | GCC_WARN_UNUSED_VARIABLE = YES; 215 | IPHONEOS_DEPLOYMENT_TARGET = 10.2; 216 | MTL_ENABLE_DEBUG_INFO = YES; 217 | ONLY_ACTIVE_ARCH = YES; 218 | SDKROOT = iphoneos; 219 | SWIFT_ACTIVE_COMPILATION_CONDITIONS = DEBUG; 220 | SWIFT_OPTIMIZATION_LEVEL = "-Onone"; 221 | TARGETED_DEVICE_FAMILY = "1,2"; 222 | }; 223 | name = Debug; 224 | }; 225 | A47B7AB31E38544800DAD9C7 /* Release */ = { 226 | isa = XCBuildConfiguration; 227 | buildSettings = { 228 | ALWAYS_SEARCH_USER_PATHS = NO; 229 | CLANG_ANALYZER_NONNULL = YES; 230 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; 231 | CLANG_CXX_LIBRARY = "libc++"; 232 | CLANG_ENABLE_MODULES = YES; 233 | CLANG_ENABLE_OBJC_ARC = YES; 234 | CLANG_WARN_BOOL_CONVERSION = YES; 235 | CLANG_WARN_CONSTANT_CONVERSION = YES; 236 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 237 | CLANG_WARN_DOCUMENTATION_COMMENTS = YES; 238 | CLANG_WARN_EMPTY_BODY = YES; 239 | CLANG_WARN_ENUM_CONVERSION = YES; 240 | CLANG_WARN_INFINITE_RECURSION = YES; 241 | CLANG_WARN_INT_CONVERSION = YES; 242 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 243 | CLANG_WARN_SUSPICIOUS_MOVE = YES; 244 | CLANG_WARN_UNREACHABLE_CODE = YES; 245 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 246 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; 247 | COPY_PHASE_STRIP = NO; 248 | DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; 249 | ENABLE_NS_ASSERTIONS = NO; 250 | ENABLE_STRICT_OBJC_MSGSEND = YES; 251 | GCC_C_LANGUAGE_STANDARD = gnu99; 252 | GCC_NO_COMMON_BLOCKS = YES; 253 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 254 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 255 | GCC_WARN_UNDECLARED_SELECTOR = YES; 256 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 257 | GCC_WARN_UNUSED_FUNCTION = YES; 258 | GCC_WARN_UNUSED_VARIABLE = YES; 259 | IPHONEOS_DEPLOYMENT_TARGET = 10.2; 260 | MTL_ENABLE_DEBUG_INFO = NO; 261 | SDKROOT = iphoneos; 262 | SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule"; 263 | TARGETED_DEVICE_FAMILY = "1,2"; 264 | VALIDATE_PRODUCT = YES; 265 | }; 266 | name = Release; 267 | }; 268 | A47B7AB51E38544800DAD9C7 /* Debug */ = { 269 | isa = XCBuildConfiguration; 270 | buildSettings = { 271 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 272 | DEVELOPMENT_TEAM = 8NQ7AXAYPG; 273 | INFOPLIST_FILE = CollectionViewAutoSizingTest/Info.plist; 274 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; 275 | PRODUCT_BUNDLE_IDENTIFIER = th.co.sun.CollectionViewAutoSizingTest; 276 | PRODUCT_NAME = "$(TARGET_NAME)"; 277 | SWIFT_VERSION = 3.0; 278 | }; 279 | name = Debug; 280 | }; 281 | A47B7AB61E38544800DAD9C7 /* Release */ = { 282 | isa = XCBuildConfiguration; 283 | buildSettings = { 284 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 285 | DEVELOPMENT_TEAM = 8NQ7AXAYPG; 286 | INFOPLIST_FILE = CollectionViewAutoSizingTest/Info.plist; 287 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; 288 | PRODUCT_BUNDLE_IDENTIFIER = th.co.sun.CollectionViewAutoSizingTest; 289 | PRODUCT_NAME = "$(TARGET_NAME)"; 290 | SWIFT_VERSION = 3.0; 291 | }; 292 | name = Release; 293 | }; 294 | /* End XCBuildConfiguration section */ 295 | 296 | /* Begin XCConfigurationList section */ 297 | A47B7A9D1E38544800DAD9C7 /* Build configuration list for PBXProject "CollectionViewAutoSizingTest" */ = { 298 | isa = XCConfigurationList; 299 | buildConfigurations = ( 300 | A47B7AB21E38544800DAD9C7 /* Debug */, 301 | A47B7AB31E38544800DAD9C7 /* Release */, 302 | ); 303 | defaultConfigurationIsVisible = 0; 304 | defaultConfigurationName = Release; 305 | }; 306 | A47B7AB41E38544800DAD9C7 /* Build configuration list for PBXNativeTarget "CollectionViewAutoSizingTest" */ = { 307 | isa = XCConfigurationList; 308 | buildConfigurations = ( 309 | A47B7AB51E38544800DAD9C7 /* Debug */, 310 | A47B7AB61E38544800DAD9C7 /* Release */, 311 | ); 312 | defaultConfigurationIsVisible = 0; 313 | }; 314 | /* End XCConfigurationList section */ 315 | }; 316 | rootObject = A47B7A9A1E38544800DAD9C7 /* Project object */; 317 | } 318 | -------------------------------------------------------------------------------- /CollectionViewAutoSizingTest.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /CollectionViewAutoSizingTest.xcodeproj/xcuserdata/sun.xcuserdatad/xcschemes/CollectionViewAutoSizingTest.xcscheme: -------------------------------------------------------------------------------- 1 | 2 | 5 | 8 | 9 | 15 | 21 | 22 | 23 | 24 | 25 | 30 | 31 | 32 | 33 | 39 | 40 | 41 | 42 | 43 | 44 | 54 | 56 | 62 | 63 | 64 | 65 | 66 | 67 | 73 | 75 | 81 | 82 | 83 | 84 | 86 | 87 | 90 | 91 | 92 | -------------------------------------------------------------------------------- /CollectionViewAutoSizingTest.xcodeproj/xcuserdata/sun.xcuserdatad/xcschemes/xcschememanagement.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | SchemeUserState 6 | 7 | CollectionViewAutoSizingTest.xcscheme 8 | 9 | orderHint 10 | 0 11 | 12 | 13 | SuppressBuildableAutocreation 14 | 15 | A47B7AA11E38544800DAD9C7 16 | 17 | primary 18 | 19 | 20 | 21 | 22 | 23 | -------------------------------------------------------------------------------- /CollectionViewAutoSizingTest/AppDelegate.swift: -------------------------------------------------------------------------------- 1 | // 2 | // AppDelegate.swift 3 | // CollectionViewAutoSizingTest 4 | // 5 | // Created by Wasin Wiwongsak on 1/25/17. 6 | // Copyright © 2017 Wasin Wiwongsak. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | 11 | @UIApplicationMain 12 | class AppDelegate: UIResponder, UIApplicationDelegate { 13 | 14 | var window: UIWindow? 15 | 16 | 17 | func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool { 18 | // Override point for customization after application launch. 19 | return true 20 | } 21 | 22 | func applicationWillResignActive(_ application: UIApplication) { 23 | // 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. 24 | // Use this method to pause ongoing tasks, disable timers, and invalidate graphics rendering callbacks. Games should use this method to pause the game. 25 | } 26 | 27 | func applicationDidEnterBackground(_ application: UIApplication) { 28 | // 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. 29 | // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits. 30 | } 31 | 32 | func applicationWillEnterForeground(_ application: UIApplication) { 33 | // Called as part of the transition from the background to the active state; here you can undo many of the changes made on entering the background. 34 | } 35 | 36 | func applicationDidBecomeActive(_ application: UIApplication) { 37 | // 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. 38 | } 39 | 40 | func applicationWillTerminate(_ application: UIApplication) { 41 | // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:. 42 | } 43 | 44 | 45 | } 46 | 47 | -------------------------------------------------------------------------------- /CollectionViewAutoSizingTest/Assets.xcassets/AppIcon.appiconset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "iphone", 5 | "size" : "29x29", 6 | "scale" : "2x" 7 | }, 8 | { 9 | "idiom" : "iphone", 10 | "size" : "29x29", 11 | "scale" : "3x" 12 | }, 13 | { 14 | "idiom" : "iphone", 15 | "size" : "40x40", 16 | "scale" : "2x" 17 | }, 18 | { 19 | "idiom" : "iphone", 20 | "size" : "40x40", 21 | "scale" : "3x" 22 | }, 23 | { 24 | "idiom" : "iphone", 25 | "size" : "60x60", 26 | "scale" : "2x" 27 | }, 28 | { 29 | "idiom" : "iphone", 30 | "size" : "60x60", 31 | "scale" : "3x" 32 | }, 33 | { 34 | "idiom" : "ipad", 35 | "size" : "29x29", 36 | "scale" : "1x" 37 | }, 38 | { 39 | "idiom" : "ipad", 40 | "size" : "29x29", 41 | "scale" : "2x" 42 | }, 43 | { 44 | "idiom" : "ipad", 45 | "size" : "40x40", 46 | "scale" : "1x" 47 | }, 48 | { 49 | "idiom" : "ipad", 50 | "size" : "40x40", 51 | "scale" : "2x" 52 | }, 53 | { 54 | "idiom" : "ipad", 55 | "size" : "76x76", 56 | "scale" : "1x" 57 | }, 58 | { 59 | "idiom" : "ipad", 60 | "size" : "76x76", 61 | "scale" : "2x" 62 | } 63 | ], 64 | "info" : { 65 | "version" : 1, 66 | "author" : "xcode" 67 | } 68 | } -------------------------------------------------------------------------------- /CollectionViewAutoSizingTest/Base.lproj/LaunchScreen.storyboard: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | -------------------------------------------------------------------------------- /CollectionViewAutoSizingTest/Base.lproj/Main.storyboard: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | -------------------------------------------------------------------------------- /CollectionViewAutoSizingTest/Cell.swift: -------------------------------------------------------------------------------- 1 | // 2 | // Cell.swift 3 | // CollectionViewAutoSizingTest 4 | // 5 | // Created by Wasin Wiwongsak on 1/25/17. 6 | // Copyright © 2017 Wasin Wiwongsak. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | 11 | class Cell: UICollectionViewCell { 12 | @IBOutlet weak var headerLabel: UILabel! 13 | @IBOutlet weak var descriptionLabel: UILabel! 14 | @IBOutlet weak var widthConstraint: NSLayoutConstraint! 15 | 16 | override func awakeFromNib() { 17 | super.awakeFromNib() 18 | // Initialization code 19 | self.contentView.translatesAutoresizingMaskIntoConstraints = false 20 | let screenWidth = UIScreen.main.bounds.size.width 21 | widthConstraint.constant = screenWidth - (2 * 12) 22 | } 23 | 24 | } 25 | -------------------------------------------------------------------------------- /CollectionViewAutoSizingTest/Cell.xib: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 30 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | -------------------------------------------------------------------------------- /CollectionViewAutoSizingTest/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleExecutable 8 | $(EXECUTABLE_NAME) 9 | CFBundleIdentifier 10 | $(PRODUCT_BUNDLE_IDENTIFIER) 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundleName 14 | $(PRODUCT_NAME) 15 | CFBundlePackageType 16 | APPL 17 | CFBundleShortVersionString 18 | 1.0 19 | CFBundleVersion 20 | 1 21 | LSRequiresIPhoneOS 22 | 23 | UILaunchStoryboardName 24 | LaunchScreen 25 | UIMainStoryboardFile 26 | Main 27 | UIRequiredDeviceCapabilities 28 | 29 | armv7 30 | 31 | UISupportedInterfaceOrientations 32 | 33 | UIInterfaceOrientationPortrait 34 | UIInterfaceOrientationLandscapeLeft 35 | UIInterfaceOrientationLandscapeRight 36 | 37 | UISupportedInterfaceOrientations~ipad 38 | 39 | UIInterfaceOrientationPortrait 40 | UIInterfaceOrientationPortraitUpsideDown 41 | UIInterfaceOrientationLandscapeLeft 42 | UIInterfaceOrientationLandscapeRight 43 | 44 | 45 | 46 | -------------------------------------------------------------------------------- /CollectionViewAutoSizingTest/ViewController.swift: -------------------------------------------------------------------------------- 1 | // 2 | // ViewController.swift 3 | // CollectionViewAutoSizingTest 4 | // 5 | // Created by Wasin Wiwongsak on 1/25/17. 6 | // Copyright © 2017 Wasin Wiwongsak. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | 11 | class ViewController: UIViewController, UICollectionViewDataSource { 12 | @IBOutlet weak var collectionView: UICollectionView! 13 | 14 | let randomTexts = ["Aenean dapibus urna a ullamcorper malesuada. Ut tempor.", 15 | "Sed venenatis ligula massa, a vulputate ipsum fringilla eget. Ut justo erat, facilisis id rhoncus cursus, fringilla at.", 16 | "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Vestibulum lobortis nibh metus, elementum tempus libero ornare vitae. Etiam sed leo pretium, consectetur turpis non, dapibus purus. Suspendisse potenti. Ut ut eros nunc. Cras nulla justo, porttitor non sapien at, iaculis.", 17 | "Maecenas pellentesque sed magna in congue. Sed non lacus in mi posuere scelerisque. Aenean.", 18 | "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Cras eget ex a velit tincidunt sodales. Donec elementum nisi at enim tempus, et rutrum erat semper. Phasellus ultricies est nec finibus."] 19 | 20 | override func viewDidLoad() { 21 | super.viewDidLoad() 22 | // Do any additional setup after loading the view, typically from a nib. 23 | collectionView.register(UINib.init(nibName: "Cell", bundle: nil), forCellWithReuseIdentifier: "Cell") 24 | if let flowLayout = collectionView.collectionViewLayout as? UICollectionViewFlowLayout { 25 | flowLayout.estimatedItemSize = CGSize(width: 1,height: 1) 26 | } 27 | collectionView.dataSource = self 28 | } 29 | 30 | override func didReceiveMemoryWarning() { 31 | super.didReceiveMemoryWarning() 32 | // Dispose of any resources that can be recreated. 33 | } 34 | 35 | public func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int { 36 | return randomTexts.count; 37 | } 38 | 39 | public func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell { 40 | let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "Cell", for: indexPath) as! Cell 41 | cell.descriptionLabel.text = randomTexts[indexPath.row] 42 | return cell 43 | } 44 | 45 | } 46 | 47 | --------------------------------------------------------------------------------