├── .gitignore ├── CollectionViewSelfSizing.xcodeproj ├── project.pbxproj └── project.xcworkspace │ ├── contents.xcworkspacedata │ └── xcshareddata │ └── IDEWorkspaceChecks.plist ├── CollectionViewSelfSizing ├── AppDelegate.swift ├── Base.lproj │ └── Main.storyboard ├── CollectionCell.swift ├── Item.swift ├── Supporting Files │ ├── Assets.xcassets │ │ ├── AppIcon.appiconset │ │ │ └── Contents.json │ │ └── Contents.json │ ├── Base.lproj │ │ └── LaunchScreen.storyboard │ └── Info.plist └── ViewController.swift ├── README.md └── demo.png /.gitignore: -------------------------------------------------------------------------------- 1 | # Xcode 2 | # 3 | # gitignore contributors: remember to update Global/Xcode.gitignore, Objective-C.gitignore & Swift.gitignore 4 | 5 | ## Build generated 6 | build/ 7 | DerivedData/ 8 | 9 | ## Various settings 10 | *.pbxuser 11 | !default.pbxuser 12 | *.mode1v3 13 | !default.mode1v3 14 | *.mode2v3 15 | !default.mode2v3 16 | *.perspectivev3 17 | !default.perspectivev3 18 | xcuserdata/ 19 | 20 | ## Other 21 | *.moved-aside 22 | *.xccheckout 23 | *.xcscmblueprint 24 | 25 | ## Obj-C/Swift specific 26 | *.hmap 27 | *.ipa 28 | *.dSYM.zip 29 | *.dSYM 30 | 31 | ## Playgrounds 32 | timeline.xctimeline 33 | playground.xcworkspace 34 | 35 | # Swift Package Manager 36 | # 37 | # Add this line if you want to avoid checking in source code from Swift Package Manager dependencies. 38 | # Packages/ 39 | # Package.pins 40 | # Package.resolved 41 | .build/ 42 | 43 | # CocoaPods 44 | # 45 | # We recommend against adding the Pods directory to your .gitignore. However 46 | # you should judge for yourself, the pros and cons are mentioned at: 47 | # https://guides.cocoapods.org/using/using-cocoapods.html#should-i-check-the-pods-directory-into-source-control 48 | # 49 | # Pods/ 50 | # 51 | # Add this line if you want to avoid checking in source code from the Xcode workspace 52 | # *.xcworkspace 53 | 54 | # Carthage 55 | # 56 | # Add this line if you want to avoid checking in source code from Carthage dependencies. 57 | # Carthage/Checkouts 58 | 59 | Carthage/Build 60 | 61 | # fastlane 62 | # 63 | # It is recommended to not store the screenshots in the git repo. Instead, use fastlane to re-generate the 64 | # screenshots whenever they are needed. 65 | # For more information about the recommended setup visit: 66 | # https://docs.fastlane.tools/best-practices/source-control/#source-control 67 | 68 | fastlane/report.xml 69 | fastlane/Preview.html 70 | fastlane/screenshots/**/*.png 71 | fastlane/test_output 72 | 73 | # Code Injection 74 | # 75 | # After new code Injection tools there's a generated folder /iOSInjectionProject 76 | # https://github.com/johnno1962/injectionforxcode 77 | 78 | iOSInjectionProject/ -------------------------------------------------------------------------------- /CollectionViewSelfSizing.xcodeproj/project.pbxproj: -------------------------------------------------------------------------------- 1 | // !$*UTF8*$! 2 | { 3 | archiveVersion = 1; 4 | classes = { 5 | }; 6 | objectVersion = 50; 7 | objects = { 8 | 9 | /* Begin PBXBuildFile section */ 10 | 801A9AB02225A0EA00F3C348 /* CollectionCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 801A9AAF2225A0EA00F3C348 /* CollectionCell.swift */; }; 11 | 8035804F220346EB00B32795 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8035804E220346EB00B32795 /* AppDelegate.swift */; }; 12 | 80358051220346EB00B32795 /* ViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 80358050220346EB00B32795 /* ViewController.swift */; }; 13 | 80358054220346EB00B32795 /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 80358052220346EB00B32795 /* Main.storyboard */; }; 14 | 80358056220346ED00B32795 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 80358055220346ED00B32795 /* Assets.xcassets */; }; 15 | 80358059220346ED00B32795 /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 80358057220346ED00B32795 /* LaunchScreen.storyboard */; }; 16 | 80C9A47C2203557C00B6D8FD /* Item.swift in Sources */ = {isa = PBXBuildFile; fileRef = 80C9A47B2203557C00B6D8FD /* Item.swift */; }; 17 | /* End PBXBuildFile section */ 18 | 19 | /* Begin PBXFileReference section */ 20 | 801A9AAF2225A0EA00F3C348 /* CollectionCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CollectionCell.swift; sourceTree = ""; }; 21 | 8035804B220346EB00B32795 /* CollectionViewSelfSizing.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = CollectionViewSelfSizing.app; sourceTree = BUILT_PRODUCTS_DIR; }; 22 | 8035804E220346EB00B32795 /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = ""; }; 23 | 80358050220346EB00B32795 /* ViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ViewController.swift; sourceTree = ""; }; 24 | 80358053220346EB00B32795 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/Main.storyboard; sourceTree = ""; }; 25 | 80358055220346ED00B32795 /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = ""; }; 26 | 80358058220346ED00B32795 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/LaunchScreen.storyboard; sourceTree = ""; }; 27 | 8035805A220346ED00B32795 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 28 | 80C9A47B2203557C00B6D8FD /* Item.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Item.swift; sourceTree = ""; }; 29 | /* End PBXFileReference section */ 30 | 31 | /* Begin PBXFrameworksBuildPhase section */ 32 | 80358048220346EB00B32795 /* Frameworks */ = { 33 | isa = PBXFrameworksBuildPhase; 34 | buildActionMask = 2147483647; 35 | files = ( 36 | ); 37 | runOnlyForDeploymentPostprocessing = 0; 38 | }; 39 | /* End PBXFrameworksBuildPhase section */ 40 | 41 | /* Begin PBXGroup section */ 42 | 80358042220346EB00B32795 = { 43 | isa = PBXGroup; 44 | children = ( 45 | 8035804D220346EB00B32795 /* CollectionViewSelfSizing */, 46 | 8035804C220346EB00B32795 /* Products */, 47 | ); 48 | sourceTree = ""; 49 | }; 50 | 8035804C220346EB00B32795 /* Products */ = { 51 | isa = PBXGroup; 52 | children = ( 53 | 8035804B220346EB00B32795 /* CollectionViewSelfSizing.app */, 54 | ); 55 | name = Products; 56 | sourceTree = ""; 57 | }; 58 | 8035804D220346EB00B32795 /* CollectionViewSelfSizing */ = { 59 | isa = PBXGroup; 60 | children = ( 61 | 8035804E220346EB00B32795 /* AppDelegate.swift */, 62 | 80358050220346EB00B32795 /* ViewController.swift */, 63 | 80C9A47B2203557C00B6D8FD /* Item.swift */, 64 | 801A9AAF2225A0EA00F3C348 /* CollectionCell.swift */, 65 | 80358052220346EB00B32795 /* Main.storyboard */, 66 | 8035806022034C5C00B32795 /* Supporting Files */, 67 | ); 68 | path = CollectionViewSelfSizing; 69 | sourceTree = ""; 70 | }; 71 | 8035806022034C5C00B32795 /* Supporting Files */ = { 72 | isa = PBXGroup; 73 | children = ( 74 | 80358055220346ED00B32795 /* Assets.xcassets */, 75 | 80358057220346ED00B32795 /* LaunchScreen.storyboard */, 76 | 8035805A220346ED00B32795 /* Info.plist */, 77 | ); 78 | path = "Supporting Files"; 79 | sourceTree = ""; 80 | }; 81 | /* End PBXGroup section */ 82 | 83 | /* Begin PBXNativeTarget section */ 84 | 8035804A220346EB00B32795 /* CollectionViewSelfSizing */ = { 85 | isa = PBXNativeTarget; 86 | buildConfigurationList = 8035805D220346ED00B32795 /* Build configuration list for PBXNativeTarget "CollectionViewSelfSizing" */; 87 | buildPhases = ( 88 | 80358047220346EB00B32795 /* Sources */, 89 | 80358048220346EB00B32795 /* Frameworks */, 90 | 80358049220346EB00B32795 /* Resources */, 91 | ); 92 | buildRules = ( 93 | ); 94 | dependencies = ( 95 | ); 96 | name = CollectionViewSelfSizing; 97 | productName = CollectionViewSelfSizing; 98 | productReference = 8035804B220346EB00B32795 /* CollectionViewSelfSizing.app */; 99 | productType = "com.apple.product-type.application"; 100 | }; 101 | /* End PBXNativeTarget section */ 102 | 103 | /* Begin PBXProject section */ 104 | 80358043220346EB00B32795 /* Project object */ = { 105 | isa = PBXProject; 106 | attributes = { 107 | LastSwiftUpdateCheck = 1010; 108 | LastUpgradeCheck = 1010; 109 | ORGANIZATIONNAME = "Vadym Bulavin"; 110 | TargetAttributes = { 111 | 8035804A220346EB00B32795 = { 112 | CreatedOnToolsVersion = 10.1; 113 | }; 114 | }; 115 | }; 116 | buildConfigurationList = 80358046220346EB00B32795 /* Build configuration list for PBXProject "CollectionViewSelfSizing" */; 117 | compatibilityVersion = "Xcode 9.3"; 118 | developmentRegion = en; 119 | hasScannedForEncodings = 0; 120 | knownRegions = ( 121 | en, 122 | Base, 123 | ); 124 | mainGroup = 80358042220346EB00B32795; 125 | productRefGroup = 8035804C220346EB00B32795 /* Products */; 126 | projectDirPath = ""; 127 | projectRoot = ""; 128 | targets = ( 129 | 8035804A220346EB00B32795 /* CollectionViewSelfSizing */, 130 | ); 131 | }; 132 | /* End PBXProject section */ 133 | 134 | /* Begin PBXResourcesBuildPhase section */ 135 | 80358049220346EB00B32795 /* Resources */ = { 136 | isa = PBXResourcesBuildPhase; 137 | buildActionMask = 2147483647; 138 | files = ( 139 | 80358059220346ED00B32795 /* LaunchScreen.storyboard in Resources */, 140 | 80358056220346ED00B32795 /* Assets.xcassets in Resources */, 141 | 80358054220346EB00B32795 /* Main.storyboard in Resources */, 142 | ); 143 | runOnlyForDeploymentPostprocessing = 0; 144 | }; 145 | /* End PBXResourcesBuildPhase section */ 146 | 147 | /* Begin PBXSourcesBuildPhase section */ 148 | 80358047220346EB00B32795 /* Sources */ = { 149 | isa = PBXSourcesBuildPhase; 150 | buildActionMask = 2147483647; 151 | files = ( 152 | 80C9A47C2203557C00B6D8FD /* Item.swift in Sources */, 153 | 80358051220346EB00B32795 /* ViewController.swift in Sources */, 154 | 8035804F220346EB00B32795 /* AppDelegate.swift in Sources */, 155 | 801A9AB02225A0EA00F3C348 /* CollectionCell.swift in Sources */, 156 | ); 157 | runOnlyForDeploymentPostprocessing = 0; 158 | }; 159 | /* End PBXSourcesBuildPhase section */ 160 | 161 | /* Begin PBXVariantGroup section */ 162 | 80358052220346EB00B32795 /* Main.storyboard */ = { 163 | isa = PBXVariantGroup; 164 | children = ( 165 | 80358053220346EB00B32795 /* Base */, 166 | ); 167 | name = Main.storyboard; 168 | sourceTree = ""; 169 | }; 170 | 80358057220346ED00B32795 /* LaunchScreen.storyboard */ = { 171 | isa = PBXVariantGroup; 172 | children = ( 173 | 80358058220346ED00B32795 /* Base */, 174 | ); 175 | name = LaunchScreen.storyboard; 176 | sourceTree = ""; 177 | }; 178 | /* End PBXVariantGroup section */ 179 | 180 | /* Begin XCBuildConfiguration section */ 181 | 8035805B220346ED00B32795 /* Debug */ = { 182 | isa = XCBuildConfiguration; 183 | buildSettings = { 184 | ALWAYS_SEARCH_USER_PATHS = NO; 185 | CLANG_ANALYZER_NONNULL = YES; 186 | CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; 187 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++14"; 188 | CLANG_CXX_LIBRARY = "libc++"; 189 | CLANG_ENABLE_MODULES = YES; 190 | CLANG_ENABLE_OBJC_ARC = YES; 191 | CLANG_ENABLE_OBJC_WEAK = YES; 192 | CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; 193 | CLANG_WARN_BOOL_CONVERSION = YES; 194 | CLANG_WARN_COMMA = YES; 195 | CLANG_WARN_CONSTANT_CONVERSION = YES; 196 | CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; 197 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 198 | CLANG_WARN_DOCUMENTATION_COMMENTS = YES; 199 | CLANG_WARN_EMPTY_BODY = YES; 200 | CLANG_WARN_ENUM_CONVERSION = YES; 201 | CLANG_WARN_INFINITE_RECURSION = YES; 202 | CLANG_WARN_INT_CONVERSION = YES; 203 | CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; 204 | CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; 205 | CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; 206 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 207 | CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; 208 | CLANG_WARN_STRICT_PROTOTYPES = YES; 209 | CLANG_WARN_SUSPICIOUS_MOVE = YES; 210 | CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE; 211 | CLANG_WARN_UNREACHABLE_CODE = YES; 212 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 213 | CODE_SIGN_IDENTITY = "iPhone Developer"; 214 | COPY_PHASE_STRIP = NO; 215 | DEBUG_INFORMATION_FORMAT = dwarf; 216 | ENABLE_STRICT_OBJC_MSGSEND = YES; 217 | ENABLE_TESTABILITY = YES; 218 | GCC_C_LANGUAGE_STANDARD = gnu11; 219 | GCC_DYNAMIC_NO_PIC = NO; 220 | GCC_NO_COMMON_BLOCKS = YES; 221 | GCC_OPTIMIZATION_LEVEL = 0; 222 | GCC_PREPROCESSOR_DEFINITIONS = ( 223 | "DEBUG=1", 224 | "$(inherited)", 225 | ); 226 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 227 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 228 | GCC_WARN_UNDECLARED_SELECTOR = YES; 229 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 230 | GCC_WARN_UNUSED_FUNCTION = YES; 231 | GCC_WARN_UNUSED_VARIABLE = YES; 232 | IPHONEOS_DEPLOYMENT_TARGET = 12.1; 233 | MTL_ENABLE_DEBUG_INFO = INCLUDE_SOURCE; 234 | MTL_FAST_MATH = YES; 235 | ONLY_ACTIVE_ARCH = YES; 236 | SDKROOT = iphoneos; 237 | SWIFT_ACTIVE_COMPILATION_CONDITIONS = DEBUG; 238 | SWIFT_OPTIMIZATION_LEVEL = "-Onone"; 239 | }; 240 | name = Debug; 241 | }; 242 | 8035805C220346ED00B32795 /* Release */ = { 243 | isa = XCBuildConfiguration; 244 | buildSettings = { 245 | ALWAYS_SEARCH_USER_PATHS = NO; 246 | CLANG_ANALYZER_NONNULL = YES; 247 | CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; 248 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++14"; 249 | CLANG_CXX_LIBRARY = "libc++"; 250 | CLANG_ENABLE_MODULES = YES; 251 | CLANG_ENABLE_OBJC_ARC = YES; 252 | CLANG_ENABLE_OBJC_WEAK = YES; 253 | CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; 254 | CLANG_WARN_BOOL_CONVERSION = YES; 255 | CLANG_WARN_COMMA = YES; 256 | CLANG_WARN_CONSTANT_CONVERSION = YES; 257 | CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; 258 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 259 | CLANG_WARN_DOCUMENTATION_COMMENTS = YES; 260 | CLANG_WARN_EMPTY_BODY = YES; 261 | CLANG_WARN_ENUM_CONVERSION = YES; 262 | CLANG_WARN_INFINITE_RECURSION = YES; 263 | CLANG_WARN_INT_CONVERSION = YES; 264 | CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; 265 | CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; 266 | CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; 267 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 268 | CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; 269 | CLANG_WARN_STRICT_PROTOTYPES = YES; 270 | CLANG_WARN_SUSPICIOUS_MOVE = YES; 271 | CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE; 272 | CLANG_WARN_UNREACHABLE_CODE = YES; 273 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 274 | CODE_SIGN_IDENTITY = "iPhone Developer"; 275 | COPY_PHASE_STRIP = NO; 276 | DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; 277 | ENABLE_NS_ASSERTIONS = NO; 278 | ENABLE_STRICT_OBJC_MSGSEND = YES; 279 | GCC_C_LANGUAGE_STANDARD = gnu11; 280 | GCC_NO_COMMON_BLOCKS = YES; 281 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 282 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 283 | GCC_WARN_UNDECLARED_SELECTOR = YES; 284 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 285 | GCC_WARN_UNUSED_FUNCTION = YES; 286 | GCC_WARN_UNUSED_VARIABLE = YES; 287 | IPHONEOS_DEPLOYMENT_TARGET = 12.1; 288 | MTL_ENABLE_DEBUG_INFO = NO; 289 | MTL_FAST_MATH = YES; 290 | SDKROOT = iphoneos; 291 | SWIFT_COMPILATION_MODE = wholemodule; 292 | SWIFT_OPTIMIZATION_LEVEL = "-O"; 293 | VALIDATE_PRODUCT = YES; 294 | }; 295 | name = Release; 296 | }; 297 | 8035805E220346ED00B32795 /* Debug */ = { 298 | isa = XCBuildConfiguration; 299 | buildSettings = { 300 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 301 | CODE_SIGN_STYLE = Automatic; 302 | INFOPLIST_FILE = "$(SRCROOT)/CollectionViewSelfSizing/Supporting Files/Info.plist"; 303 | LD_RUNPATH_SEARCH_PATHS = ( 304 | "$(inherited)", 305 | "@executable_path/Frameworks", 306 | ); 307 | PRODUCT_BUNDLE_IDENTIFIER = V8tr.CollectionViewSelfSizing; 308 | PRODUCT_NAME = "$(TARGET_NAME)"; 309 | SWIFT_VERSION = 4.2; 310 | TARGETED_DEVICE_FAMILY = "1,2"; 311 | }; 312 | name = Debug; 313 | }; 314 | 8035805F220346ED00B32795 /* Release */ = { 315 | isa = XCBuildConfiguration; 316 | buildSettings = { 317 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 318 | CODE_SIGN_STYLE = Automatic; 319 | INFOPLIST_FILE = "$(SRCROOT)/CollectionViewSelfSizing/Supporting Files/Info.plist"; 320 | LD_RUNPATH_SEARCH_PATHS = ( 321 | "$(inherited)", 322 | "@executable_path/Frameworks", 323 | ); 324 | PRODUCT_BUNDLE_IDENTIFIER = V8tr.CollectionViewSelfSizing; 325 | PRODUCT_NAME = "$(TARGET_NAME)"; 326 | SWIFT_VERSION = 4.2; 327 | TARGETED_DEVICE_FAMILY = "1,2"; 328 | }; 329 | name = Release; 330 | }; 331 | /* End XCBuildConfiguration section */ 332 | 333 | /* Begin XCConfigurationList section */ 334 | 80358046220346EB00B32795 /* Build configuration list for PBXProject "CollectionViewSelfSizing" */ = { 335 | isa = XCConfigurationList; 336 | buildConfigurations = ( 337 | 8035805B220346ED00B32795 /* Debug */, 338 | 8035805C220346ED00B32795 /* Release */, 339 | ); 340 | defaultConfigurationIsVisible = 0; 341 | defaultConfigurationName = Release; 342 | }; 343 | 8035805D220346ED00B32795 /* Build configuration list for PBXNativeTarget "CollectionViewSelfSizing" */ = { 344 | isa = XCConfigurationList; 345 | buildConfigurations = ( 346 | 8035805E220346ED00B32795 /* Debug */, 347 | 8035805F220346ED00B32795 /* Release */, 348 | ); 349 | defaultConfigurationIsVisible = 0; 350 | defaultConfigurationName = Release; 351 | }; 352 | /* End XCConfigurationList section */ 353 | }; 354 | rootObject = 80358043220346EB00B32795 /* Project object */; 355 | } 356 | -------------------------------------------------------------------------------- /CollectionViewSelfSizing.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /CollectionViewSelfSizing.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | IDEDidComputeMac32BitWarning 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /CollectionViewSelfSizing/AppDelegate.swift: -------------------------------------------------------------------------------- 1 | // 2 | // AppDelegate.swift 3 | // CollectionViewSelfSizing 4 | // 5 | // Created by Vadym Bulavin on 1/31/19. 6 | // Copyright © 2019 Vadym Bulavin. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | 11 | @UIApplicationMain 12 | class AppDelegate: UIResponder, UIApplicationDelegate { 13 | 14 | var window: UIWindow? 15 | 16 | func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool { 17 | // Override point for customization after application launch. 18 | return true 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /CollectionViewSelfSizing/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 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | -------------------------------------------------------------------------------- /CollectionViewSelfSizing/CollectionCell.swift: -------------------------------------------------------------------------------- 1 | // 2 | // CollectionCell.swift 3 | // CollectionViewSelfSizing 4 | // 5 | // Created by Vadym Bulavin on 2/26/19. 6 | // Copyright © 2019 Vadym Bulavin. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | 11 | class CollectionCell: UICollectionViewCell { 12 | @IBOutlet weak var titleLabel: UILabel! 13 | 14 | // Note: must be strong 15 | @IBOutlet private var maxWidthConstraint: NSLayoutConstraint! { 16 | didSet { 17 | maxWidthConstraint.isActive = false 18 | } 19 | } 20 | 21 | var maxWidth: CGFloat? = nil { 22 | didSet { 23 | guard let maxWidth = maxWidth else { 24 | return 25 | } 26 | maxWidthConstraint.isActive = true 27 | maxWidthConstraint.constant = maxWidth 28 | } 29 | } 30 | 31 | override func awakeFromNib() { 32 | super.awakeFromNib() 33 | 34 | contentView.translatesAutoresizingMaskIntoConstraints = false 35 | 36 | NSLayoutConstraint.activate([ 37 | contentView.leftAnchor.constraint(equalTo: leftAnchor), 38 | contentView.rightAnchor.constraint(equalTo: rightAnchor), 39 | contentView.topAnchor.constraint(equalTo: topAnchor), 40 | contentView.bottomAnchor.constraint(equalTo: bottomAnchor) 41 | ]) 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /CollectionViewSelfSizing/Item.swift: -------------------------------------------------------------------------------- 1 | // 2 | // Item.swift 3 | // CollectionViewSelfSizing 4 | // 5 | // Created by Vadym Bulavin on 1/31/19. 6 | // Copyright © 2019 Vadym Bulavin. All rights reserved. 7 | // 8 | 9 | import Foundation 10 | 11 | struct Item { 12 | let title: String 13 | } 14 | -------------------------------------------------------------------------------- /CollectionViewSelfSizing/Supporting Files/Assets.xcassets/AppIcon.appiconset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "iphone", 5 | "size" : "20x20", 6 | "scale" : "2x" 7 | }, 8 | { 9 | "idiom" : "iphone", 10 | "size" : "20x20", 11 | "scale" : "3x" 12 | }, 13 | { 14 | "idiom" : "iphone", 15 | "size" : "29x29", 16 | "scale" : "2x" 17 | }, 18 | { 19 | "idiom" : "iphone", 20 | "size" : "29x29", 21 | "scale" : "3x" 22 | }, 23 | { 24 | "idiom" : "iphone", 25 | "size" : "40x40", 26 | "scale" : "2x" 27 | }, 28 | { 29 | "idiom" : "iphone", 30 | "size" : "40x40", 31 | "scale" : "3x" 32 | }, 33 | { 34 | "idiom" : "iphone", 35 | "size" : "60x60", 36 | "scale" : "2x" 37 | }, 38 | { 39 | "idiom" : "iphone", 40 | "size" : "60x60", 41 | "scale" : "3x" 42 | }, 43 | { 44 | "idiom" : "ipad", 45 | "size" : "20x20", 46 | "scale" : "1x" 47 | }, 48 | { 49 | "idiom" : "ipad", 50 | "size" : "20x20", 51 | "scale" : "2x" 52 | }, 53 | { 54 | "idiom" : "ipad", 55 | "size" : "29x29", 56 | "scale" : "1x" 57 | }, 58 | { 59 | "idiom" : "ipad", 60 | "size" : "29x29", 61 | "scale" : "2x" 62 | }, 63 | { 64 | "idiom" : "ipad", 65 | "size" : "40x40", 66 | "scale" : "1x" 67 | }, 68 | { 69 | "idiom" : "ipad", 70 | "size" : "40x40", 71 | "scale" : "2x" 72 | }, 73 | { 74 | "idiom" : "ipad", 75 | "size" : "76x76", 76 | "scale" : "1x" 77 | }, 78 | { 79 | "idiom" : "ipad", 80 | "size" : "76x76", 81 | "scale" : "2x" 82 | }, 83 | { 84 | "idiom" : "ipad", 85 | "size" : "83.5x83.5", 86 | "scale" : "2x" 87 | }, 88 | { 89 | "idiom" : "ios-marketing", 90 | "size" : "1024x1024", 91 | "scale" : "1x" 92 | } 93 | ], 94 | "info" : { 95 | "version" : 1, 96 | "author" : "xcode" 97 | } 98 | } -------------------------------------------------------------------------------- /CollectionViewSelfSizing/Supporting Files/Assets.xcassets/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "info" : { 3 | "version" : 1, 4 | "author" : "xcode" 5 | } 6 | } -------------------------------------------------------------------------------- /CollectionViewSelfSizing/Supporting Files/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 | -------------------------------------------------------------------------------- /CollectionViewSelfSizing/Supporting Files/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | $(DEVELOPMENT_LANGUAGE) 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 | -------------------------------------------------------------------------------- /CollectionViewSelfSizing/ViewController.swift: -------------------------------------------------------------------------------- 1 | // 2 | // ViewController.swift 3 | // CollectionViewSelfSizing 4 | // 5 | // Created by Vadym Bulavin on 1/31/19. 6 | // Copyright © 2019 Vadym Bulavin. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | 11 | class ViewController: UIViewController { 12 | 13 | @IBOutlet weak var collectionLayout: UICollectionViewFlowLayout! { 14 | didSet { 15 | collectionLayout.estimatedItemSize = UICollectionViewFlowLayout.automaticSize 16 | } 17 | } 18 | 19 | let items: [Item] = [ 20 | Item(title: "Lorem ipsum dolor sit amet, consectetur"), 21 | Item(title: "adipiscing elit, sed do eiusmod tempor"), 22 | Item(title: "incididunt ut labore et dolore magna aliqua"), 23 | Item(title: "Ut enim ad minim veniam"), 24 | Item(title: "Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum."), 25 | Item(title: "Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.") 26 | ] 27 | } 28 | 29 | // MARK: - Collection view delegate and data source methods 30 | 31 | extension ViewController: UICollectionViewDataSource, UICollectionViewDelegateFlowLayout { 32 | 33 | func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int { 34 | return items.count 35 | } 36 | 37 | func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell { 38 | let cell = collectionView.dequeueReusableCell(withReuseIdentifier: Constants.reuseID, for: indexPath) as! CollectionCell 39 | 40 | cell.titleLabel.text = items[indexPath.item].title 41 | cell.layer.borderWidth = Constants.borderWidth 42 | cell.layer.borderColor = UIColor.lightGray.cgColor 43 | cell.maxWidth = collectionView.bounds.width - Constants.spacing 44 | 45 | return cell 46 | } 47 | } 48 | 49 | // MARK: - Constants 50 | 51 | private enum Constants { 52 | static let spacing: CGFloat = 16 53 | static let borderWidth: CGFloat = 0.5 54 | static let reuseID = "CollectionCell" 55 | } 56 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # CollectionViewSelfSizing-Final 2 | [![@V8tr](https://img.shields.io/badge/contact-@V8tr-blue.svg?style=flat)](https://twitter.com/V8tr) 3 | 4 | The project demonstrates how to enable automatic self-sizing for collection view cells by means of Auto Layout. 5 | 6 |

7 | Collection view self-sizing cells 8 |

9 | 10 | See blog post 'Collection View Cells Self-Sizing' for more details: http://www.vadimbulavin.com/collection-view-cells-self-sizing/ 11 | -------------------------------------------------------------------------------- /demo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/V8tr/CollectionViewSelfSizing-Final/ec97137ba84a546eebdb3ddaaf39d979a6c90df5/demo.png --------------------------------------------------------------------------------