├── final ├── CollectionViewLayoutExample.xcodeproj │ ├── project.pbxproj │ ├── project.xcworkspace │ │ ├── contents.xcworkspacedata │ │ ├── xcshareddata │ │ │ └── IDEWorkspaceChecks.plist │ │ └── xcuserdata │ │ │ └── fernando.moyaderivas.xcuserdatad │ │ │ └── UserInterfaceState.xcuserstate │ └── xcuserdata │ │ └── fernando.moyaderivas.xcuserdatad │ │ ├── xcdebugger │ │ └── Breakpoints_v2.xcbkptlist │ │ └── xcschemes │ │ └── xcschememanagement.plist └── CollectionViewLayoutExample │ ├── GridCollectionViewLayout.swift │ ├── MainViewController.swift │ ├── Support │ ├── AppDelegate.swift │ ├── Assets.xcassets │ │ ├── AppIcon.appiconset │ │ │ └── Contents.json │ │ └── Contents.json │ ├── Base.lproj │ │ └── LaunchScreen.storyboard │ ├── Info.plist │ └── SceneDelegate.swift │ └── Views │ ├── GridColletionViewCell.swift │ └── GridSuplementaryView.swift └── starter ├── CollectionViewLayoutExample.xcodeproj ├── project.pbxproj ├── project.xcworkspace │ ├── contents.xcworkspacedata │ ├── xcshareddata │ │ └── IDEWorkspaceChecks.plist │ └── xcuserdata │ │ └── fernando.moyaderivas.xcuserdatad │ │ └── UserInterfaceState.xcuserstate └── xcuserdata │ └── fernando.moyaderivas.xcuserdatad │ ├── xcdebugger │ └── Breakpoints_v2.xcbkptlist │ └── xcschemes │ └── xcschememanagement.plist └── CollectionViewLayoutExample ├── MainViewController.swift ├── Support ├── AppDelegate.swift ├── Assets.xcassets │ ├── AppIcon.appiconset │ │ └── Contents.json │ └── Contents.json ├── Base.lproj │ └── LaunchScreen.storyboard ├── Info.plist └── SceneDelegate.swift └── Views ├── GridColletionViewCell.swift └── GridSuplementaryView.swift /final/CollectionViewLayoutExample.xcodeproj/project.pbxproj: -------------------------------------------------------------------------------- 1 | // !$*UTF8*$! 2 | { 3 | archiveVersion = 1; 4 | classes = { 5 | }; 6 | objectVersion = 50; 7 | objects = { 8 | 9 | /* Begin PBXBuildFile section */ 10 | 6B01666E2444CC8E00101E0C /* GridColletionViewCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6B01666D2444CC8E00101E0C /* GridColletionViewCell.swift */; }; 11 | 6B80AD96243A3144000F4785 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6B80AD95243A3144000F4785 /* AppDelegate.swift */; }; 12 | 6B80AD98243A3144000F4785 /* SceneDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6B80AD97243A3144000F4785 /* SceneDelegate.swift */; }; 13 | 6B80AD9A243A3144000F4785 /* MainViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6B80AD99243A3144000F4785 /* MainViewController.swift */; }; 14 | 6B80AD9F243A3145000F4785 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 6B80AD9E243A3145000F4785 /* Assets.xcassets */; }; 15 | 6B80ADA2243A3145000F4785 /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 6B80ADA0243A3145000F4785 /* LaunchScreen.storyboard */; }; 16 | 6B80ADAC243A3401000F4785 /* GridSuplementaryView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6B80ADAB243A3401000F4785 /* GridSuplementaryView.swift */; }; 17 | 6B80ADAE243A4BFD000F4785 /* GridCollectionViewLayout.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6B80ADAD243A4BFD000F4785 /* GridCollectionViewLayout.swift */; }; 18 | /* End PBXBuildFile section */ 19 | 20 | /* Begin PBXFileReference section */ 21 | 6B01666D2444CC8E00101E0C /* GridColletionViewCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = GridColletionViewCell.swift; sourceTree = ""; }; 22 | 6B80AD92243A3144000F4785 /* CollectionViewLayoutExample.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = CollectionViewLayoutExample.app; sourceTree = BUILT_PRODUCTS_DIR; }; 23 | 6B80AD95243A3144000F4785 /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = ""; }; 24 | 6B80AD97243A3144000F4785 /* SceneDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SceneDelegate.swift; sourceTree = ""; }; 25 | 6B80AD99243A3144000F4785 /* MainViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MainViewController.swift; sourceTree = ""; }; 26 | 6B80AD9E243A3145000F4785 /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = ""; }; 27 | 6B80ADA1243A3145000F4785 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/LaunchScreen.storyboard; sourceTree = ""; }; 28 | 6B80ADA3243A3145000F4785 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 29 | 6B80ADAB243A3401000F4785 /* GridSuplementaryView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = GridSuplementaryView.swift; sourceTree = ""; }; 30 | 6B80ADAD243A4BFD000F4785 /* GridCollectionViewLayout.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = GridCollectionViewLayout.swift; sourceTree = ""; }; 31 | /* End PBXFileReference section */ 32 | 33 | /* Begin PBXFrameworksBuildPhase section */ 34 | 6B80AD8F243A3144000F4785 /* Frameworks */ = { 35 | isa = PBXFrameworksBuildPhase; 36 | buildActionMask = 2147483647; 37 | files = ( 38 | ); 39 | runOnlyForDeploymentPostprocessing = 0; 40 | }; 41 | /* End PBXFrameworksBuildPhase section */ 42 | 43 | /* Begin PBXGroup section */ 44 | 6B80AD89243A3144000F4785 = { 45 | isa = PBXGroup; 46 | children = ( 47 | 6B80AD94243A3144000F4785 /* CollectionViewLayoutExample */, 48 | 6B80AD93243A3144000F4785 /* Products */, 49 | ); 50 | sourceTree = ""; 51 | }; 52 | 6B80AD93243A3144000F4785 /* Products */ = { 53 | isa = PBXGroup; 54 | children = ( 55 | 6B80AD92243A3144000F4785 /* CollectionViewLayoutExample.app */, 56 | ); 57 | name = Products; 58 | sourceTree = ""; 59 | }; 60 | 6B80AD94243A3144000F4785 /* CollectionViewLayoutExample */ = { 61 | isa = PBXGroup; 62 | children = ( 63 | 6B80ADAA243A33DB000F4785 /* Views */, 64 | 6B80ADA9243A33A3000F4785 /* Support */, 65 | 6B80AD99243A3144000F4785 /* MainViewController.swift */, 66 | 6B80ADAD243A4BFD000F4785 /* GridCollectionViewLayout.swift */, 67 | ); 68 | path = CollectionViewLayoutExample; 69 | sourceTree = ""; 70 | }; 71 | 6B80ADA9243A33A3000F4785 /* Support */ = { 72 | isa = PBXGroup; 73 | children = ( 74 | 6B80AD95243A3144000F4785 /* AppDelegate.swift */, 75 | 6B80AD97243A3144000F4785 /* SceneDelegate.swift */, 76 | 6B80AD9E243A3145000F4785 /* Assets.xcassets */, 77 | 6B80ADA0243A3145000F4785 /* LaunchScreen.storyboard */, 78 | 6B80ADA3243A3145000F4785 /* Info.plist */, 79 | ); 80 | path = Support; 81 | sourceTree = ""; 82 | }; 83 | 6B80ADAA243A33DB000F4785 /* Views */ = { 84 | isa = PBXGroup; 85 | children = ( 86 | 6B80ADAB243A3401000F4785 /* GridSuplementaryView.swift */, 87 | 6B01666D2444CC8E00101E0C /* GridColletionViewCell.swift */, 88 | ); 89 | path = Views; 90 | sourceTree = ""; 91 | }; 92 | /* End PBXGroup section */ 93 | 94 | /* Begin PBXNativeTarget section */ 95 | 6B80AD91243A3144000F4785 /* CollectionViewLayoutExample */ = { 96 | isa = PBXNativeTarget; 97 | buildConfigurationList = 6B80ADA6243A3145000F4785 /* Build configuration list for PBXNativeTarget "CollectionViewLayoutExample" */; 98 | buildPhases = ( 99 | 6B80AD8E243A3144000F4785 /* Sources */, 100 | 6B80AD8F243A3144000F4785 /* Frameworks */, 101 | 6B80AD90243A3144000F4785 /* Resources */, 102 | ); 103 | buildRules = ( 104 | ); 105 | dependencies = ( 106 | ); 107 | name = CollectionViewLayoutExample; 108 | productName = CollectionViewLayoutExample; 109 | productReference = 6B80AD92243A3144000F4785 /* CollectionViewLayoutExample.app */; 110 | productType = "com.apple.product-type.application"; 111 | }; 112 | /* End PBXNativeTarget section */ 113 | 114 | /* Begin PBXProject section */ 115 | 6B80AD8A243A3144000F4785 /* Project object */ = { 116 | isa = PBXProject; 117 | attributes = { 118 | LastSwiftUpdateCheck = 1140; 119 | LastUpgradeCheck = 1140; 120 | ORGANIZATIONNAME = "Fernando Moya de Rivas"; 121 | TargetAttributes = { 122 | 6B80AD91243A3144000F4785 = { 123 | CreatedOnToolsVersion = 11.4; 124 | }; 125 | }; 126 | }; 127 | buildConfigurationList = 6B80AD8D243A3144000F4785 /* Build configuration list for PBXProject "CollectionViewLayoutExample" */; 128 | compatibilityVersion = "Xcode 9.3"; 129 | developmentRegion = en; 130 | hasScannedForEncodings = 0; 131 | knownRegions = ( 132 | en, 133 | Base, 134 | ); 135 | mainGroup = 6B80AD89243A3144000F4785; 136 | productRefGroup = 6B80AD93243A3144000F4785 /* Products */; 137 | projectDirPath = ""; 138 | projectRoot = ""; 139 | targets = ( 140 | 6B80AD91243A3144000F4785 /* CollectionViewLayoutExample */, 141 | ); 142 | }; 143 | /* End PBXProject section */ 144 | 145 | /* Begin PBXResourcesBuildPhase section */ 146 | 6B80AD90243A3144000F4785 /* Resources */ = { 147 | isa = PBXResourcesBuildPhase; 148 | buildActionMask = 2147483647; 149 | files = ( 150 | 6B80ADA2243A3145000F4785 /* LaunchScreen.storyboard in Resources */, 151 | 6B80AD9F243A3145000F4785 /* Assets.xcassets in Resources */, 152 | ); 153 | runOnlyForDeploymentPostprocessing = 0; 154 | }; 155 | /* End PBXResourcesBuildPhase section */ 156 | 157 | /* Begin PBXSourcesBuildPhase section */ 158 | 6B80AD8E243A3144000F4785 /* Sources */ = { 159 | isa = PBXSourcesBuildPhase; 160 | buildActionMask = 2147483647; 161 | files = ( 162 | 6B01666E2444CC8E00101E0C /* GridColletionViewCell.swift in Sources */, 163 | 6B80AD9A243A3144000F4785 /* MainViewController.swift in Sources */, 164 | 6B80AD96243A3144000F4785 /* AppDelegate.swift in Sources */, 165 | 6B80AD98243A3144000F4785 /* SceneDelegate.swift in Sources */, 166 | 6B80ADAC243A3401000F4785 /* GridSuplementaryView.swift in Sources */, 167 | 6B80ADAE243A4BFD000F4785 /* GridCollectionViewLayout.swift in Sources */, 168 | ); 169 | runOnlyForDeploymentPostprocessing = 0; 170 | }; 171 | /* End PBXSourcesBuildPhase section */ 172 | 173 | /* Begin PBXVariantGroup section */ 174 | 6B80ADA0243A3145000F4785 /* LaunchScreen.storyboard */ = { 175 | isa = PBXVariantGroup; 176 | children = ( 177 | 6B80ADA1243A3145000F4785 /* Base */, 178 | ); 179 | name = LaunchScreen.storyboard; 180 | sourceTree = ""; 181 | }; 182 | /* End PBXVariantGroup section */ 183 | 184 | /* Begin XCBuildConfiguration section */ 185 | 6B80ADA4243A3145000F4785 /* Debug */ = { 186 | isa = XCBuildConfiguration; 187 | buildSettings = { 188 | ALWAYS_SEARCH_USER_PATHS = NO; 189 | CLANG_ANALYZER_NONNULL = YES; 190 | CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; 191 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++14"; 192 | CLANG_CXX_LIBRARY = "libc++"; 193 | CLANG_ENABLE_MODULES = YES; 194 | CLANG_ENABLE_OBJC_ARC = YES; 195 | CLANG_ENABLE_OBJC_WEAK = YES; 196 | CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; 197 | CLANG_WARN_BOOL_CONVERSION = YES; 198 | CLANG_WARN_COMMA = YES; 199 | CLANG_WARN_CONSTANT_CONVERSION = YES; 200 | CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; 201 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 202 | CLANG_WARN_DOCUMENTATION_COMMENTS = YES; 203 | CLANG_WARN_EMPTY_BODY = YES; 204 | CLANG_WARN_ENUM_CONVERSION = YES; 205 | CLANG_WARN_INFINITE_RECURSION = YES; 206 | CLANG_WARN_INT_CONVERSION = YES; 207 | CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; 208 | CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; 209 | CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; 210 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 211 | CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; 212 | CLANG_WARN_STRICT_PROTOTYPES = YES; 213 | CLANG_WARN_SUSPICIOUS_MOVE = YES; 214 | CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE; 215 | CLANG_WARN_UNREACHABLE_CODE = YES; 216 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 217 | COPY_PHASE_STRIP = NO; 218 | DEBUG_INFORMATION_FORMAT = dwarf; 219 | ENABLE_STRICT_OBJC_MSGSEND = YES; 220 | ENABLE_TESTABILITY = YES; 221 | GCC_C_LANGUAGE_STANDARD = gnu11; 222 | GCC_DYNAMIC_NO_PIC = NO; 223 | GCC_NO_COMMON_BLOCKS = YES; 224 | GCC_OPTIMIZATION_LEVEL = 0; 225 | GCC_PREPROCESSOR_DEFINITIONS = ( 226 | "DEBUG=1", 227 | "$(inherited)", 228 | ); 229 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 230 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 231 | GCC_WARN_UNDECLARED_SELECTOR = YES; 232 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 233 | GCC_WARN_UNUSED_FUNCTION = YES; 234 | GCC_WARN_UNUSED_VARIABLE = YES; 235 | IPHONEOS_DEPLOYMENT_TARGET = 13.4; 236 | MTL_ENABLE_DEBUG_INFO = INCLUDE_SOURCE; 237 | MTL_FAST_MATH = YES; 238 | ONLY_ACTIVE_ARCH = YES; 239 | SDKROOT = iphoneos; 240 | SWIFT_ACTIVE_COMPILATION_CONDITIONS = DEBUG; 241 | SWIFT_OPTIMIZATION_LEVEL = "-Onone"; 242 | }; 243 | name = Debug; 244 | }; 245 | 6B80ADA5243A3145000F4785 /* Release */ = { 246 | isa = XCBuildConfiguration; 247 | buildSettings = { 248 | ALWAYS_SEARCH_USER_PATHS = NO; 249 | CLANG_ANALYZER_NONNULL = YES; 250 | CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; 251 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++14"; 252 | CLANG_CXX_LIBRARY = "libc++"; 253 | CLANG_ENABLE_MODULES = YES; 254 | CLANG_ENABLE_OBJC_ARC = YES; 255 | CLANG_ENABLE_OBJC_WEAK = YES; 256 | CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; 257 | CLANG_WARN_BOOL_CONVERSION = YES; 258 | CLANG_WARN_COMMA = YES; 259 | CLANG_WARN_CONSTANT_CONVERSION = YES; 260 | CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; 261 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 262 | CLANG_WARN_DOCUMENTATION_COMMENTS = YES; 263 | CLANG_WARN_EMPTY_BODY = YES; 264 | CLANG_WARN_ENUM_CONVERSION = YES; 265 | CLANG_WARN_INFINITE_RECURSION = YES; 266 | CLANG_WARN_INT_CONVERSION = YES; 267 | CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; 268 | CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; 269 | CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; 270 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 271 | CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; 272 | CLANG_WARN_STRICT_PROTOTYPES = YES; 273 | CLANG_WARN_SUSPICIOUS_MOVE = YES; 274 | CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE; 275 | CLANG_WARN_UNREACHABLE_CODE = YES; 276 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 277 | COPY_PHASE_STRIP = NO; 278 | DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; 279 | ENABLE_NS_ASSERTIONS = NO; 280 | ENABLE_STRICT_OBJC_MSGSEND = YES; 281 | GCC_C_LANGUAGE_STANDARD = gnu11; 282 | GCC_NO_COMMON_BLOCKS = YES; 283 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 284 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 285 | GCC_WARN_UNDECLARED_SELECTOR = YES; 286 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 287 | GCC_WARN_UNUSED_FUNCTION = YES; 288 | GCC_WARN_UNUSED_VARIABLE = YES; 289 | IPHONEOS_DEPLOYMENT_TARGET = 13.4; 290 | MTL_ENABLE_DEBUG_INFO = NO; 291 | MTL_FAST_MATH = YES; 292 | SDKROOT = iphoneos; 293 | SWIFT_COMPILATION_MODE = wholemodule; 294 | SWIFT_OPTIMIZATION_LEVEL = "-O"; 295 | VALIDATE_PRODUCT = YES; 296 | }; 297 | name = Release; 298 | }; 299 | 6B80ADA7243A3145000F4785 /* Debug */ = { 300 | isa = XCBuildConfiguration; 301 | buildSettings = { 302 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 303 | CODE_SIGN_STYLE = Automatic; 304 | DEVELOPMENT_TEAM = FMMUM2Q3NC; 305 | INFOPLIST_FILE = CollectionViewLayoutExample/Support/Info.plist; 306 | IPHONEOS_DEPLOYMENT_TARGET = 13.0; 307 | LD_RUNPATH_SEARCH_PATHS = ( 308 | "$(inherited)", 309 | "@executable_path/Frameworks", 310 | ); 311 | PRODUCT_BUNDLE_IDENTIFIER = com.fmoyader.example.CollectionViewLayoutExample; 312 | PRODUCT_NAME = "$(TARGET_NAME)"; 313 | SWIFT_VERSION = 5.0; 314 | TARGETED_DEVICE_FAMILY = "1,2"; 315 | }; 316 | name = Debug; 317 | }; 318 | 6B80ADA8243A3145000F4785 /* Release */ = { 319 | isa = XCBuildConfiguration; 320 | buildSettings = { 321 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 322 | CODE_SIGN_STYLE = Automatic; 323 | DEVELOPMENT_TEAM = FMMUM2Q3NC; 324 | INFOPLIST_FILE = CollectionViewLayoutExample/Support/Info.plist; 325 | IPHONEOS_DEPLOYMENT_TARGET = 13.0; 326 | LD_RUNPATH_SEARCH_PATHS = ( 327 | "$(inherited)", 328 | "@executable_path/Frameworks", 329 | ); 330 | PRODUCT_BUNDLE_IDENTIFIER = com.fmoyader.example.CollectionViewLayoutExample; 331 | PRODUCT_NAME = "$(TARGET_NAME)"; 332 | SWIFT_VERSION = 5.0; 333 | TARGETED_DEVICE_FAMILY = "1,2"; 334 | }; 335 | name = Release; 336 | }; 337 | /* End XCBuildConfiguration section */ 338 | 339 | /* Begin XCConfigurationList section */ 340 | 6B80AD8D243A3144000F4785 /* Build configuration list for PBXProject "CollectionViewLayoutExample" */ = { 341 | isa = XCConfigurationList; 342 | buildConfigurations = ( 343 | 6B80ADA4243A3145000F4785 /* Debug */, 344 | 6B80ADA5243A3145000F4785 /* Release */, 345 | ); 346 | defaultConfigurationIsVisible = 0; 347 | defaultConfigurationName = Release; 348 | }; 349 | 6B80ADA6243A3145000F4785 /* Build configuration list for PBXNativeTarget "CollectionViewLayoutExample" */ = { 350 | isa = XCConfigurationList; 351 | buildConfigurations = ( 352 | 6B80ADA7243A3145000F4785 /* Debug */, 353 | 6B80ADA8243A3145000F4785 /* Release */, 354 | ); 355 | defaultConfigurationIsVisible = 0; 356 | defaultConfigurationName = Release; 357 | }; 358 | /* End XCConfigurationList section */ 359 | }; 360 | rootObject = 6B80AD8A243A3144000F4785 /* Project object */; 361 | } 362 | -------------------------------------------------------------------------------- /final/CollectionViewLayoutExample.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /final/CollectionViewLayoutExample.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | IDEDidComputeMac32BitWarning 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /final/CollectionViewLayoutExample.xcodeproj/project.xcworkspace/xcuserdata/fernando.moyaderivas.xcuserdatad/UserInterfaceState.xcuserstate: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fermoya/CollectionViewLayoutExample/9b6ead798a35ef1cb48e8fe559606badd13a54e3/final/CollectionViewLayoutExample.xcodeproj/project.xcworkspace/xcuserdata/fernando.moyaderivas.xcuserdatad/UserInterfaceState.xcuserstate -------------------------------------------------------------------------------- /final/CollectionViewLayoutExample.xcodeproj/xcuserdata/fernando.moyaderivas.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist: -------------------------------------------------------------------------------- 1 | 2 | 6 | 7 | -------------------------------------------------------------------------------- /final/CollectionViewLayoutExample.xcodeproj/xcuserdata/fernando.moyaderivas.xcuserdatad/xcschemes/xcschememanagement.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | SchemeUserState 6 | 7 | CollectionViewLayoutExample.xcscheme_^#shared#^_ 8 | 9 | orderHint 10 | 0 11 | 12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /final/CollectionViewLayoutExample/GridCollectionViewLayout.swift: -------------------------------------------------------------------------------- 1 | // 2 | // SpannableCollectionViewLayout.swift 3 | // CollectionViewLayoutExample 4 | // 5 | // Created by Fernando Moya de Rivas on 05/04/2020. 6 | // Copyright © 2020 Fernando Moya de Rivas. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | 11 | protocol GridCollectionViewLayoutDelegate: class { 12 | func collectionView(_ collectionView: UICollectionView, columnSpanForItemAt index: GridIndex, indexPath: IndexPath) -> Int 13 | func collectionView(_ collectionView: UICollectionView, heightForItemAt index: GridIndex, indexPath: IndexPath) -> CGFloat 14 | func collectionView(_ collectionView: UICollectionView, heightForRow row: Int) -> CGFloat 15 | func collectionView(_ collectionView: UICollectionView, heightForSupplementaryView kind: GridCollectionViewLayout.ElementKind, at section: Int) -> CGFloat? 16 | func collectionView(_ collectionView: UICollectionView, alignmentForSection section: Int) -> GridCollectionViewLayout.Alignment 17 | } 18 | 19 | class GridLayoutAttributes: UICollectionViewLayoutAttributes { 20 | var index: GridIndex? 21 | } 22 | 23 | struct GridIndex { 24 | let row: Int 25 | let column: Int 26 | } 27 | 28 | class GridCollectionViewLayout: UICollectionViewLayout { 29 | 30 | enum Alignment: String { 31 | case top, bottom, center 32 | } 33 | 34 | enum ElementKind: String { 35 | case header = "elementKindHeader" 36 | case footer = "elementKindFooter" 37 | case cell = "elementKindCell" 38 | } 39 | 40 | weak var delegate: GridCollectionViewLayoutDelegate? 41 | 42 | var cellAlignment: Alignment = .center 43 | var columnSpacing: CGFloat = 8 44 | var rowSpacing: CGFloat = 16 45 | var sectionSpacing: CGFloat = 32 46 | 47 | var estimatedColumnSpan = 1 48 | var estimatedCellHeight: CGFloat = 60 49 | 50 | private(set) var numberOfColumns: Int 51 | private var attributes: [ElementKind: [IndexPath: GridLayoutAttributes]] = [:] 52 | 53 | init(numberOfColumns: Int) { 54 | self.numberOfColumns = numberOfColumns 55 | super.init() 56 | } 57 | 58 | required init?(coder: NSCoder) { 59 | self.numberOfColumns = coder.value(forKey: "numberOfColumns") as? Int ?? 3 60 | super.init(coder: coder) 61 | } 62 | 63 | private var collectionViewWidth: CGFloat { 64 | guard let collectionView = collectionView else { return .zero } 65 | return collectionView.bounds.width - (collectionView.contentInset.left + collectionView.contentInset.right) 66 | } 67 | 68 | private var collectionViewHeight: CGFloat = 0 69 | 70 | override var collectionViewContentSize: CGSize { 71 | return CGSize(width: collectionViewWidth, height: collectionViewHeight) 72 | } 73 | 74 | private func reset() { 75 | self.attributes = [.cell: [:], .header: [:], .footer: [:]] 76 | } 77 | 78 | override func prepare() { 79 | super.prepare() 80 | 81 | guard let collectionView = collectionView else { return } 82 | guard attributes.isEmpty else { return } 83 | guard numberOfColumns > 0 else { return } 84 | 85 | reset() 86 | 87 | let numberOfSections = collectionView.numberOfSections 88 | (0.. 0 { 108 | let columnWidth = (collectionViewWidth - CGFloat(numberOfColumns - 1) * columnSpacing) / CGFloat(numberOfColumns) 109 | let columnHeight = delegate?.collectionView(collectionView, heightForRow: row) ?? estimatedCellHeight 110 | 111 | var availableSpan = numberOfColumns 112 | (0.. 0, availableSpan + column == numberOfColumns else { return } 115 | let indexPath = IndexPath(item: itemIndex, section: section) 116 | let index = GridIndex(row: row, column: column) 117 | 118 | let cellSpan = min(availableSpan, delegate?.collectionView(collectionView, columnSpanForItemAt: index, indexPath: indexPath) ?? estimatedColumnSpan) 119 | 120 | let cellWidth = columnWidth * CGFloat(cellSpan) + CGFloat(cellSpan - 1) * columnSpacing 121 | let cellHeight = min(columnHeight, delegate?.collectionView(collectionView, heightForItemAt: index, indexPath: indexPath) ?? estimatedCellHeight) 122 | 123 | let cellXPosition = CGFloat(column) * (columnWidth + columnSpacing) 124 | let cellYPosition: CGFloat 125 | switch alignment { 126 | case .top: 127 | cellYPosition = collectionViewHeight 128 | case .bottom: 129 | cellYPosition = collectionViewHeight + (columnHeight - cellHeight) 130 | case .center: 131 | cellYPosition = collectionViewHeight + (columnHeight - cellHeight) / 2 132 | } 133 | 134 | let cellOrigin = CGPoint(x: cellXPosition, y: cellYPosition) 135 | let cellSize = CGSize(width: cellWidth, height: cellHeight) 136 | 137 | let attributes = GridLayoutAttributes(forCellWith: indexPath) 138 | attributes.index = index 139 | attributes.frame = CGRect(origin: cellOrigin, size: cellSize) 140 | 141 | self.attributes[.cell]?[indexPath] = attributes 142 | 143 | itemIndex += 1 144 | availableSpan -= cellSpan 145 | } 146 | 147 | row += 1 148 | collectionViewHeight += columnHeight 149 | 150 | guard itemIndex < itemsCount else { continue } 151 | collectionViewHeight += rowSpacing 152 | } 153 | } 154 | 155 | private func prepareSuplementaryView(kind: ElementKind, at section: Int) { 156 | guard let collectionView = collectionView else { return } 157 | guard let height = delegate?.collectionView(collectionView, heightForSupplementaryView: kind, at: section) else { return } 158 | 159 | let indexPath = IndexPath(row: 0, section: section) 160 | let attributes = GridLayoutAttributes(forSupplementaryViewOfKind: kind.rawValue, with: indexPath) 161 | attributes.frame = CGRect(x: 0, y: collectionViewHeight, width: collectionViewWidth, height: height) 162 | self.attributes[kind]?[indexPath] = attributes 163 | 164 | collectionViewHeight += height 165 | } 166 | 167 | override func invalidateLayout() { 168 | super.invalidateLayout() 169 | collectionViewHeight = 0 170 | attributes.removeAll() 171 | } 172 | 173 | override func layoutAttributesForElements(in rect: CGRect) -> [UICollectionViewLayoutAttributes]? { 174 | return attributes.values.flatMap { $0.values }.filter { $0.frame.intersects(rect) } 175 | } 176 | 177 | override func layoutAttributesForSupplementaryView(ofKind elementKind: String, at indexPath: IndexPath) -> UICollectionViewLayoutAttributes? { 178 | guard let kind = ElementKind(rawValue: elementKind) else { return nil } 179 | return attributes[kind]?[indexPath] 180 | } 181 | 182 | override func layoutAttributesForItem(at indexPath: IndexPath) -> UICollectionViewLayoutAttributes? { 183 | return attributes[.cell]?[indexPath] 184 | } 185 | 186 | override public func shouldInvalidateLayout(forBoundsChange newBounds: CGRect) -> Bool { 187 | guard let oldBounds = collectionView?.bounds else { return false } 188 | return oldBounds.size != newBounds.size 189 | } 190 | 191 | } 192 | -------------------------------------------------------------------------------- /final/CollectionViewLayoutExample/MainViewController.swift: -------------------------------------------------------------------------------- 1 | // 2 | // ViewController.swift 3 | // CollectionViewLayoutExample 4 | // 5 | // Created by Fernando Moya de Rivas on 05/04/2020. 6 | // Copyright © 2020 Fernando Moya de Rivas. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | 11 | class MainViewController: UICollectionViewController { 12 | 13 | private let numberOfSections = 4 14 | private let numberOfItemsInSection = [13, 10, 9, 16] 15 | private let cellIdentifier = "SpannableCollectionViewExampleCell" 16 | private let headerIdentifier = "SpannableCollectionViewExampleHeader" 17 | private let footerIdentifier = "SpannableCollectionViewExampleFooter" 18 | 19 | private let columnSpans = [[1, 1, 1, 1], [2, 2], [3, 1], [1, 2, 1]] 20 | private let alignments: [GridCollectionViewLayout.Alignment] = [.top, .bottom, .center, .top] 21 | 22 | init() { 23 | let layout = GridCollectionViewLayout(numberOfColumns: 4) 24 | super.init(collectionViewLayout: layout) 25 | layout.delegate = self 26 | } 27 | 28 | required init?(coder: NSCoder) { 29 | fatalError("init(coder:) has not been implemented") 30 | } 31 | 32 | override func viewDidLoad() { 33 | super.viewDidLoad() 34 | 35 | collectionView.register(GridColletionViewCell.self, forCellWithReuseIdentifier: cellIdentifier) 36 | collectionView.register(GridSuplementaryView.self, forSupplementaryViewOfKind: GridCollectionViewLayout.ElementKind.header.rawValue, withReuseIdentifier: headerIdentifier) 37 | collectionView.register(GridSuplementaryView.self, forSupplementaryViewOfKind: GridCollectionViewLayout.ElementKind.footer.rawValue, withReuseIdentifier: footerIdentifier) 38 | } 39 | 40 | private func colorForCell(at indexPath: IndexPath) -> UIColor { 41 | let colors: [UIColor] = [.blue, .brown, .green, .red] 42 | return colors[indexPath.row % colors.count] 43 | } 44 | 45 | } 46 | 47 | // MARK: UICollectionViewDataSource 48 | 49 | extension MainViewController { 50 | 51 | override func numberOfSections(in collectionView: UICollectionView) -> Int { 52 | return numberOfSections 53 | } 54 | 55 | override func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int { 56 | return numberOfItemsInSection[section] 57 | } 58 | 59 | override func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell { 60 | let cell = collectionView.dequeueReusableCell(withReuseIdentifier: cellIdentifier, for: indexPath) as! GridColletionViewCell 61 | cell.text = "(\(indexPath.section),\(indexPath.row))" 62 | cell.backgroundColor = colorForCell(at: indexPath) 63 | return cell 64 | } 65 | 66 | } 67 | 68 | // MARK: UICollectionViewDelegate 69 | 70 | extension MainViewController { 71 | 72 | override func collectionView(_ collectionView: UICollectionView, viewForSupplementaryElementOfKind kind: String, at indexPath: IndexPath) -> UICollectionReusableView { 73 | guard let elementKind = GridCollectionViewLayout.ElementKind(rawValue: kind) else { fatalError("Unknown element kind") } 74 | guard elementKind != .cell else { fatalError("Suplementary cell can't be a cell") } 75 | 76 | let identifier = elementKind == .header ? headerIdentifier : footerIdentifier 77 | guard let view = collectionView.dequeueReusableSupplementaryView(ofKind: elementKind.rawValue, withReuseIdentifier: identifier, for: indexPath) as? GridSuplementaryView else { fatalError("Couldn't dequeue UICollectionView header") } 78 | 79 | let alignment = self.collectionView(collectionView, alignmentForSection: indexPath.section) 80 | let title = elementKind == .header ? "Section \(indexPath.section + 1): \(columnSpans[indexPath.section])" : "alignment \(alignment.rawValue)" 81 | 82 | view.title = title 83 | return view 84 | } 85 | 86 | } 87 | 88 | // MARK: SpannableCollectionViewLayoutDelegate 89 | 90 | extension MainViewController: GridCollectionViewLayoutDelegate { 91 | 92 | func collectionView(_ collectionView: UICollectionView, heightForItemAt index: GridIndex, indexPath: IndexPath) -> CGFloat { 93 | let columnHeight = self.collectionView(collectionView, heightForRow: index.row) 94 | return (index.column + index.row).isMultiple(of: 4) ? columnHeight : columnHeight - 20 95 | } 96 | 97 | func collectionView(_ collectionView: UICollectionView, heightForRow row: Int) -> CGFloat { 98 | return row.isMultiple(of: 2) ? 100 : 60 99 | } 100 | 101 | func collectionView(_ collectionView: UICollectionView, heightForSupplementaryView kind: GridCollectionViewLayout.ElementKind, at section: Int) -> CGFloat? { 102 | return 40 103 | } 104 | 105 | func collectionView(_ collectionView: UICollectionView, alignmentForSection section: Int) -> GridCollectionViewLayout.Alignment { 106 | return alignments[section] 107 | } 108 | 109 | 110 | func collectionView(_ collectionView: UICollectionView, columnSpanForItemAt index: GridIndex, indexPath: IndexPath) -> Int { 111 | let spans = columnSpans[indexPath.section] 112 | let span = spans[indexPath.row % spans.count] 113 | return span 114 | } 115 | 116 | } 117 | -------------------------------------------------------------------------------- /final/CollectionViewLayoutExample/Support/AppDelegate.swift: -------------------------------------------------------------------------------- 1 | // 2 | // AppDelegate.swift 3 | // CollectionViewLayoutExample 4 | // 5 | // Created by Fernando Moya de Rivas on 05/04/2020. 6 | // Copyright © 2020 Fernando Moya de Rivas. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | 11 | @UIApplicationMain 12 | class AppDelegate: UIResponder, UIApplicationDelegate { 13 | 14 | func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool { 15 | // Override point for customization after application launch. 16 | return true 17 | } 18 | 19 | // MARK: UISceneSession Lifecycle 20 | 21 | func application(_ application: UIApplication, configurationForConnecting connectingSceneSession: UISceneSession, options: UIScene.ConnectionOptions) -> UISceneConfiguration { 22 | // Called when a new scene session is being created. 23 | // Use this method to select a configuration to create the new scene with. 24 | return UISceneConfiguration(name: "Default Configuration", sessionRole: connectingSceneSession.role) 25 | } 26 | 27 | } 28 | 29 | -------------------------------------------------------------------------------- /final/CollectionViewLayoutExample/Support/Assets.xcassets/AppIcon.appiconset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "iphone", 5 | "scale" : "2x", 6 | "size" : "20x20" 7 | }, 8 | { 9 | "idiom" : "iphone", 10 | "scale" : "3x", 11 | "size" : "20x20" 12 | }, 13 | { 14 | "idiom" : "iphone", 15 | "scale" : "2x", 16 | "size" : "29x29" 17 | }, 18 | { 19 | "idiom" : "iphone", 20 | "scale" : "3x", 21 | "size" : "29x29" 22 | }, 23 | { 24 | "idiom" : "iphone", 25 | "scale" : "2x", 26 | "size" : "40x40" 27 | }, 28 | { 29 | "idiom" : "iphone", 30 | "scale" : "3x", 31 | "size" : "40x40" 32 | }, 33 | { 34 | "idiom" : "iphone", 35 | "scale" : "2x", 36 | "size" : "60x60" 37 | }, 38 | { 39 | "idiom" : "iphone", 40 | "scale" : "3x", 41 | "size" : "60x60" 42 | }, 43 | { 44 | "idiom" : "ipad", 45 | "scale" : "1x", 46 | "size" : "20x20" 47 | }, 48 | { 49 | "idiom" : "ipad", 50 | "scale" : "2x", 51 | "size" : "20x20" 52 | }, 53 | { 54 | "idiom" : "ipad", 55 | "scale" : "1x", 56 | "size" : "29x29" 57 | }, 58 | { 59 | "idiom" : "ipad", 60 | "scale" : "2x", 61 | "size" : "29x29" 62 | }, 63 | { 64 | "idiom" : "ipad", 65 | "scale" : "1x", 66 | "size" : "40x40" 67 | }, 68 | { 69 | "idiom" : "ipad", 70 | "scale" : "2x", 71 | "size" : "40x40" 72 | }, 73 | { 74 | "idiom" : "ipad", 75 | "scale" : "1x", 76 | "size" : "76x76" 77 | }, 78 | { 79 | "idiom" : "ipad", 80 | "scale" : "2x", 81 | "size" : "76x76" 82 | }, 83 | { 84 | "idiom" : "ipad", 85 | "scale" : "2x", 86 | "size" : "83.5x83.5" 87 | }, 88 | { 89 | "idiom" : "ios-marketing", 90 | "scale" : "1x", 91 | "size" : "1024x1024" 92 | } 93 | ], 94 | "info" : { 95 | "author" : "xcode", 96 | "version" : 1 97 | } 98 | } 99 | -------------------------------------------------------------------------------- /final/CollectionViewLayoutExample/Support/Assets.xcassets/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "info" : { 3 | "author" : "xcode", 4 | "version" : 1 5 | } 6 | } 7 | -------------------------------------------------------------------------------- /final/CollectionViewLayoutExample/Support/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 | -------------------------------------------------------------------------------- /final/CollectionViewLayoutExample/Support/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 | $(PRODUCT_BUNDLE_PACKAGE_TYPE) 17 | CFBundleShortVersionString 18 | 1.0 19 | CFBundleVersion 20 | 1 21 | LSRequiresIPhoneOS 22 | 23 | UIApplicationSceneManifest 24 | 25 | UIApplicationSupportsMultipleScenes 26 | 27 | UISceneConfigurations 28 | 29 | UIWindowSceneSessionRoleApplication 30 | 31 | 32 | UISceneConfigurationName 33 | Default Configuration 34 | UISceneDelegateClassName 35 | $(PRODUCT_MODULE_NAME).SceneDelegate 36 | 37 | 38 | 39 | 40 | UILaunchStoryboardName 41 | LaunchScreen 42 | UIRequiredDeviceCapabilities 43 | 44 | armv7 45 | 46 | UISupportedInterfaceOrientations 47 | 48 | UIInterfaceOrientationPortrait 49 | UIInterfaceOrientationLandscapeLeft 50 | UIInterfaceOrientationLandscapeRight 51 | 52 | UISupportedInterfaceOrientations~ipad 53 | 54 | UIInterfaceOrientationPortrait 55 | UIInterfaceOrientationPortraitUpsideDown 56 | UIInterfaceOrientationLandscapeLeft 57 | UIInterfaceOrientationLandscapeRight 58 | 59 | 60 | 61 | -------------------------------------------------------------------------------- /final/CollectionViewLayoutExample/Support/SceneDelegate.swift: -------------------------------------------------------------------------------- 1 | // 2 | // SceneDelegate.swift 3 | // CollectionViewLayoutExample 4 | // 5 | // Created by Fernando Moya de Rivas on 05/04/2020. 6 | // Copyright © 2020 Fernando Moya de Rivas. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | 11 | class SceneDelegate: UIResponder, UIWindowSceneDelegate { 12 | 13 | var window: UIWindow? 14 | 15 | func scene(_ scene: UIScene, willConnectTo session: UISceneSession, options connectionOptions: UIScene.ConnectionOptions) { 16 | 17 | if let windowScene = scene as? UIWindowScene { 18 | let window = UIWindow(windowScene: windowScene) 19 | window.rootViewController = MainViewController() 20 | self.window = window 21 | window.makeKeyAndVisible() 22 | } 23 | 24 | } 25 | 26 | } 27 | 28 | -------------------------------------------------------------------------------- /final/CollectionViewLayoutExample/Views/GridColletionViewCell.swift: -------------------------------------------------------------------------------- 1 | // 2 | // MattrixColletionViewCell.swift 3 | // CollectionViewLayoutExample 4 | // 5 | // Created by Fernando Moya de Rivas on 13/04/2020. 6 | // Copyright © 2020 Fernando Moya de Rivas. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | 11 | class GridColletionViewCell: UICollectionViewCell { 12 | 13 | var text: String = "" { 14 | didSet { 15 | titlelLabel.text = text 16 | } 17 | } 18 | 19 | private var titlelLabel: UILabel = { 20 | let label = UILabel() 21 | label.textColor = .white 22 | label.font = .systemFont(ofSize: 11) 23 | label.numberOfLines = 0 24 | label.textAlignment = .left 25 | return label 26 | }() 27 | 28 | override func didMoveToWindow() { 29 | super.didMoveToWindow() 30 | if contentView.subviews.isEmpty { contentView.addSubview(titlelLabel) } 31 | } 32 | 33 | override func layoutSubviews() { 34 | super.layoutSubviews() 35 | titlelLabel.frame = contentView.bounds 36 | } 37 | 38 | } 39 | 40 | -------------------------------------------------------------------------------- /final/CollectionViewLayoutExample/Views/GridSuplementaryView.swift: -------------------------------------------------------------------------------- 1 | // 2 | // SectionTitleView.swift 3 | // CollectionViewLayoutExample 4 | // 5 | // Created by Fernando Moya de Rivas on 05/04/2020. 6 | // Copyright © 2020 Fernando Moya de Rivas. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | 11 | class GridSuplementaryView: UICollectionReusableView { 12 | 13 | var title: String? { 14 | set { 15 | titleLabel.text = newValue 16 | } 17 | get { titleLabel.text } 18 | } 19 | 20 | private lazy var titleLabel: UILabel = { 21 | let label = UILabel() 22 | label.translatesAutoresizingMaskIntoConstraints = false 23 | label.textColor = .systemGray 24 | label.font = .systemFont(ofSize: 25, weight: .medium) 25 | return label 26 | }() 27 | 28 | override func didMoveToWindow() { 29 | super.didMoveToWindow() 30 | 31 | guard subviews.isEmpty else { return } 32 | 33 | addSubview(titleLabel) 34 | NSLayoutConstraint.activate([ 35 | titleLabel.centerYAnchor.constraint(equalTo: centerYAnchor), 36 | titleLabel.leadingAnchor.constraint(equalTo: leadingAnchor, constant: 16) 37 | ]) 38 | } 39 | 40 | } 41 | -------------------------------------------------------------------------------- /starter/CollectionViewLayoutExample.xcodeproj/project.pbxproj: -------------------------------------------------------------------------------- 1 | // !$*UTF8*$! 2 | { 3 | archiveVersion = 1; 4 | classes = { 5 | }; 6 | objectVersion = 50; 7 | objects = { 8 | 9 | /* Begin PBXBuildFile section */ 10 | 6B01666E2444CC8E00101E0C /* GridColletionViewCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6B01666D2444CC8E00101E0C /* GridColletionViewCell.swift */; }; 11 | 6B80AD96243A3144000F4785 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6B80AD95243A3144000F4785 /* AppDelegate.swift */; }; 12 | 6B80AD98243A3144000F4785 /* SceneDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6B80AD97243A3144000F4785 /* SceneDelegate.swift */; }; 13 | 6B80AD9A243A3144000F4785 /* MainViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6B80AD99243A3144000F4785 /* MainViewController.swift */; }; 14 | 6B80AD9F243A3145000F4785 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 6B80AD9E243A3145000F4785 /* Assets.xcassets */; }; 15 | 6B80ADA2243A3145000F4785 /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 6B80ADA0243A3145000F4785 /* LaunchScreen.storyboard */; }; 16 | 6B80ADAC243A3401000F4785 /* GridSuplementaryView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6B80ADAB243A3401000F4785 /* GridSuplementaryView.swift */; }; 17 | /* End PBXBuildFile section */ 18 | 19 | /* Begin PBXFileReference section */ 20 | 6B01666D2444CC8E00101E0C /* GridColletionViewCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = GridColletionViewCell.swift; sourceTree = ""; }; 21 | 6B80AD92243A3144000F4785 /* CollectionViewLayoutExample.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = CollectionViewLayoutExample.app; sourceTree = BUILT_PRODUCTS_DIR; }; 22 | 6B80AD95243A3144000F4785 /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = ""; }; 23 | 6B80AD97243A3144000F4785 /* SceneDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SceneDelegate.swift; sourceTree = ""; }; 24 | 6B80AD99243A3144000F4785 /* MainViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MainViewController.swift; sourceTree = ""; }; 25 | 6B80AD9E243A3145000F4785 /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = ""; }; 26 | 6B80ADA1243A3145000F4785 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/LaunchScreen.storyboard; sourceTree = ""; }; 27 | 6B80ADA3243A3145000F4785 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 28 | 6B80ADAB243A3401000F4785 /* GridSuplementaryView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = GridSuplementaryView.swift; sourceTree = ""; }; 29 | /* End PBXFileReference section */ 30 | 31 | /* Begin PBXFrameworksBuildPhase section */ 32 | 6B80AD8F243A3144000F4785 /* Frameworks */ = { 33 | isa = PBXFrameworksBuildPhase; 34 | buildActionMask = 2147483647; 35 | files = ( 36 | ); 37 | runOnlyForDeploymentPostprocessing = 0; 38 | }; 39 | /* End PBXFrameworksBuildPhase section */ 40 | 41 | /* Begin PBXGroup section */ 42 | 6B80AD89243A3144000F4785 = { 43 | isa = PBXGroup; 44 | children = ( 45 | 6B80AD94243A3144000F4785 /* CollectionViewLayoutExample */, 46 | 6B80AD93243A3144000F4785 /* Products */, 47 | ); 48 | sourceTree = ""; 49 | }; 50 | 6B80AD93243A3144000F4785 /* Products */ = { 51 | isa = PBXGroup; 52 | children = ( 53 | 6B80AD92243A3144000F4785 /* CollectionViewLayoutExample.app */, 54 | ); 55 | name = Products; 56 | sourceTree = ""; 57 | }; 58 | 6B80AD94243A3144000F4785 /* CollectionViewLayoutExample */ = { 59 | isa = PBXGroup; 60 | children = ( 61 | 6B80ADAA243A33DB000F4785 /* Views */, 62 | 6B80ADA9243A33A3000F4785 /* Support */, 63 | 6B80AD99243A3144000F4785 /* MainViewController.swift */, 64 | ); 65 | path = CollectionViewLayoutExample; 66 | sourceTree = ""; 67 | }; 68 | 6B80ADA9243A33A3000F4785 /* Support */ = { 69 | isa = PBXGroup; 70 | children = ( 71 | 6B80AD95243A3144000F4785 /* AppDelegate.swift */, 72 | 6B80AD97243A3144000F4785 /* SceneDelegate.swift */, 73 | 6B80AD9E243A3145000F4785 /* Assets.xcassets */, 74 | 6B80ADA0243A3145000F4785 /* LaunchScreen.storyboard */, 75 | 6B80ADA3243A3145000F4785 /* Info.plist */, 76 | ); 77 | path = Support; 78 | sourceTree = ""; 79 | }; 80 | 6B80ADAA243A33DB000F4785 /* Views */ = { 81 | isa = PBXGroup; 82 | children = ( 83 | 6B80ADAB243A3401000F4785 /* GridSuplementaryView.swift */, 84 | 6B01666D2444CC8E00101E0C /* GridColletionViewCell.swift */, 85 | ); 86 | path = Views; 87 | sourceTree = ""; 88 | }; 89 | /* End PBXGroup section */ 90 | 91 | /* Begin PBXNativeTarget section */ 92 | 6B80AD91243A3144000F4785 /* CollectionViewLayoutExample */ = { 93 | isa = PBXNativeTarget; 94 | buildConfigurationList = 6B80ADA6243A3145000F4785 /* Build configuration list for PBXNativeTarget "CollectionViewLayoutExample" */; 95 | buildPhases = ( 96 | 6B80AD8E243A3144000F4785 /* Sources */, 97 | 6B80AD8F243A3144000F4785 /* Frameworks */, 98 | 6B80AD90243A3144000F4785 /* Resources */, 99 | ); 100 | buildRules = ( 101 | ); 102 | dependencies = ( 103 | ); 104 | name = CollectionViewLayoutExample; 105 | productName = CollectionViewLayoutExample; 106 | productReference = 6B80AD92243A3144000F4785 /* CollectionViewLayoutExample.app */; 107 | productType = "com.apple.product-type.application"; 108 | }; 109 | /* End PBXNativeTarget section */ 110 | 111 | /* Begin PBXProject section */ 112 | 6B80AD8A243A3144000F4785 /* Project object */ = { 113 | isa = PBXProject; 114 | attributes = { 115 | LastSwiftUpdateCheck = 1140; 116 | LastUpgradeCheck = 1140; 117 | ORGANIZATIONNAME = "Fernando Moya de Rivas"; 118 | TargetAttributes = { 119 | 6B80AD91243A3144000F4785 = { 120 | CreatedOnToolsVersion = 11.4; 121 | }; 122 | }; 123 | }; 124 | buildConfigurationList = 6B80AD8D243A3144000F4785 /* Build configuration list for PBXProject "CollectionViewLayoutExample" */; 125 | compatibilityVersion = "Xcode 9.3"; 126 | developmentRegion = en; 127 | hasScannedForEncodings = 0; 128 | knownRegions = ( 129 | en, 130 | Base, 131 | ); 132 | mainGroup = 6B80AD89243A3144000F4785; 133 | productRefGroup = 6B80AD93243A3144000F4785 /* Products */; 134 | projectDirPath = ""; 135 | projectRoot = ""; 136 | targets = ( 137 | 6B80AD91243A3144000F4785 /* CollectionViewLayoutExample */, 138 | ); 139 | }; 140 | /* End PBXProject section */ 141 | 142 | /* Begin PBXResourcesBuildPhase section */ 143 | 6B80AD90243A3144000F4785 /* Resources */ = { 144 | isa = PBXResourcesBuildPhase; 145 | buildActionMask = 2147483647; 146 | files = ( 147 | 6B80ADA2243A3145000F4785 /* LaunchScreen.storyboard in Resources */, 148 | 6B80AD9F243A3145000F4785 /* Assets.xcassets in Resources */, 149 | ); 150 | runOnlyForDeploymentPostprocessing = 0; 151 | }; 152 | /* End PBXResourcesBuildPhase section */ 153 | 154 | /* Begin PBXSourcesBuildPhase section */ 155 | 6B80AD8E243A3144000F4785 /* Sources */ = { 156 | isa = PBXSourcesBuildPhase; 157 | buildActionMask = 2147483647; 158 | files = ( 159 | 6B01666E2444CC8E00101E0C /* GridColletionViewCell.swift in Sources */, 160 | 6B80AD9A243A3144000F4785 /* MainViewController.swift in Sources */, 161 | 6B80AD96243A3144000F4785 /* AppDelegate.swift in Sources */, 162 | 6B80AD98243A3144000F4785 /* SceneDelegate.swift in Sources */, 163 | 6B80ADAC243A3401000F4785 /* GridSuplementaryView.swift in Sources */, 164 | ); 165 | runOnlyForDeploymentPostprocessing = 0; 166 | }; 167 | /* End PBXSourcesBuildPhase section */ 168 | 169 | /* Begin PBXVariantGroup section */ 170 | 6B80ADA0243A3145000F4785 /* LaunchScreen.storyboard */ = { 171 | isa = PBXVariantGroup; 172 | children = ( 173 | 6B80ADA1243A3145000F4785 /* Base */, 174 | ); 175 | name = LaunchScreen.storyboard; 176 | sourceTree = ""; 177 | }; 178 | /* End PBXVariantGroup section */ 179 | 180 | /* Begin XCBuildConfiguration section */ 181 | 6B80ADA4243A3145000F4785 /* 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 | COPY_PHASE_STRIP = NO; 214 | DEBUG_INFORMATION_FORMAT = dwarf; 215 | ENABLE_STRICT_OBJC_MSGSEND = YES; 216 | ENABLE_TESTABILITY = YES; 217 | GCC_C_LANGUAGE_STANDARD = gnu11; 218 | GCC_DYNAMIC_NO_PIC = NO; 219 | GCC_NO_COMMON_BLOCKS = YES; 220 | GCC_OPTIMIZATION_LEVEL = 0; 221 | GCC_PREPROCESSOR_DEFINITIONS = ( 222 | "DEBUG=1", 223 | "$(inherited)", 224 | ); 225 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 226 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 227 | GCC_WARN_UNDECLARED_SELECTOR = YES; 228 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 229 | GCC_WARN_UNUSED_FUNCTION = YES; 230 | GCC_WARN_UNUSED_VARIABLE = YES; 231 | IPHONEOS_DEPLOYMENT_TARGET = 13.4; 232 | MTL_ENABLE_DEBUG_INFO = INCLUDE_SOURCE; 233 | MTL_FAST_MATH = YES; 234 | ONLY_ACTIVE_ARCH = YES; 235 | SDKROOT = iphoneos; 236 | SWIFT_ACTIVE_COMPILATION_CONDITIONS = DEBUG; 237 | SWIFT_OPTIMIZATION_LEVEL = "-Onone"; 238 | }; 239 | name = Debug; 240 | }; 241 | 6B80ADA5243A3145000F4785 /* Release */ = { 242 | isa = XCBuildConfiguration; 243 | buildSettings = { 244 | ALWAYS_SEARCH_USER_PATHS = NO; 245 | CLANG_ANALYZER_NONNULL = YES; 246 | CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; 247 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++14"; 248 | CLANG_CXX_LIBRARY = "libc++"; 249 | CLANG_ENABLE_MODULES = YES; 250 | CLANG_ENABLE_OBJC_ARC = YES; 251 | CLANG_ENABLE_OBJC_WEAK = YES; 252 | CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; 253 | CLANG_WARN_BOOL_CONVERSION = YES; 254 | CLANG_WARN_COMMA = YES; 255 | CLANG_WARN_CONSTANT_CONVERSION = YES; 256 | CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; 257 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 258 | CLANG_WARN_DOCUMENTATION_COMMENTS = YES; 259 | CLANG_WARN_EMPTY_BODY = YES; 260 | CLANG_WARN_ENUM_CONVERSION = YES; 261 | CLANG_WARN_INFINITE_RECURSION = YES; 262 | CLANG_WARN_INT_CONVERSION = YES; 263 | CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; 264 | CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; 265 | CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; 266 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 267 | CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; 268 | CLANG_WARN_STRICT_PROTOTYPES = YES; 269 | CLANG_WARN_SUSPICIOUS_MOVE = YES; 270 | CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE; 271 | CLANG_WARN_UNREACHABLE_CODE = YES; 272 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 273 | COPY_PHASE_STRIP = NO; 274 | DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; 275 | ENABLE_NS_ASSERTIONS = NO; 276 | ENABLE_STRICT_OBJC_MSGSEND = YES; 277 | GCC_C_LANGUAGE_STANDARD = gnu11; 278 | GCC_NO_COMMON_BLOCKS = YES; 279 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 280 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 281 | GCC_WARN_UNDECLARED_SELECTOR = YES; 282 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 283 | GCC_WARN_UNUSED_FUNCTION = YES; 284 | GCC_WARN_UNUSED_VARIABLE = YES; 285 | IPHONEOS_DEPLOYMENT_TARGET = 13.4; 286 | MTL_ENABLE_DEBUG_INFO = NO; 287 | MTL_FAST_MATH = YES; 288 | SDKROOT = iphoneos; 289 | SWIFT_COMPILATION_MODE = wholemodule; 290 | SWIFT_OPTIMIZATION_LEVEL = "-O"; 291 | VALIDATE_PRODUCT = YES; 292 | }; 293 | name = Release; 294 | }; 295 | 6B80ADA7243A3145000F4785 /* Debug */ = { 296 | isa = XCBuildConfiguration; 297 | buildSettings = { 298 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 299 | CODE_SIGN_STYLE = Automatic; 300 | DEVELOPMENT_TEAM = FMMUM2Q3NC; 301 | INFOPLIST_FILE = CollectionViewLayoutExample/Support/Info.plist; 302 | IPHONEOS_DEPLOYMENT_TARGET = 13.0; 303 | LD_RUNPATH_SEARCH_PATHS = ( 304 | "$(inherited)", 305 | "@executable_path/Frameworks", 306 | ); 307 | PRODUCT_BUNDLE_IDENTIFIER = com.fmoyader.example.CollectionViewLayoutExample; 308 | PRODUCT_NAME = "$(TARGET_NAME)"; 309 | SWIFT_VERSION = 5.0; 310 | TARGETED_DEVICE_FAMILY = "1,2"; 311 | }; 312 | name = Debug; 313 | }; 314 | 6B80ADA8243A3145000F4785 /* Release */ = { 315 | isa = XCBuildConfiguration; 316 | buildSettings = { 317 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 318 | CODE_SIGN_STYLE = Automatic; 319 | DEVELOPMENT_TEAM = FMMUM2Q3NC; 320 | INFOPLIST_FILE = CollectionViewLayoutExample/Support/Info.plist; 321 | IPHONEOS_DEPLOYMENT_TARGET = 13.0; 322 | LD_RUNPATH_SEARCH_PATHS = ( 323 | "$(inherited)", 324 | "@executable_path/Frameworks", 325 | ); 326 | PRODUCT_BUNDLE_IDENTIFIER = com.fmoyader.example.CollectionViewLayoutExample; 327 | PRODUCT_NAME = "$(TARGET_NAME)"; 328 | SWIFT_VERSION = 5.0; 329 | TARGETED_DEVICE_FAMILY = "1,2"; 330 | }; 331 | name = Release; 332 | }; 333 | /* End XCBuildConfiguration section */ 334 | 335 | /* Begin XCConfigurationList section */ 336 | 6B80AD8D243A3144000F4785 /* Build configuration list for PBXProject "CollectionViewLayoutExample" */ = { 337 | isa = XCConfigurationList; 338 | buildConfigurations = ( 339 | 6B80ADA4243A3145000F4785 /* Debug */, 340 | 6B80ADA5243A3145000F4785 /* Release */, 341 | ); 342 | defaultConfigurationIsVisible = 0; 343 | defaultConfigurationName = Release; 344 | }; 345 | 6B80ADA6243A3145000F4785 /* Build configuration list for PBXNativeTarget "CollectionViewLayoutExample" */ = { 346 | isa = XCConfigurationList; 347 | buildConfigurations = ( 348 | 6B80ADA7243A3145000F4785 /* Debug */, 349 | 6B80ADA8243A3145000F4785 /* Release */, 350 | ); 351 | defaultConfigurationIsVisible = 0; 352 | defaultConfigurationName = Release; 353 | }; 354 | /* End XCConfigurationList section */ 355 | }; 356 | rootObject = 6B80AD8A243A3144000F4785 /* Project object */; 357 | } 358 | -------------------------------------------------------------------------------- /starter/CollectionViewLayoutExample.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /starter/CollectionViewLayoutExample.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | IDEDidComputeMac32BitWarning 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /starter/CollectionViewLayoutExample.xcodeproj/project.xcworkspace/xcuserdata/fernando.moyaderivas.xcuserdatad/UserInterfaceState.xcuserstate: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fermoya/CollectionViewLayoutExample/9b6ead798a35ef1cb48e8fe559606badd13a54e3/starter/CollectionViewLayoutExample.xcodeproj/project.xcworkspace/xcuserdata/fernando.moyaderivas.xcuserdatad/UserInterfaceState.xcuserstate -------------------------------------------------------------------------------- /starter/CollectionViewLayoutExample.xcodeproj/xcuserdata/fernando.moyaderivas.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist: -------------------------------------------------------------------------------- 1 | 2 | 6 | 7 | -------------------------------------------------------------------------------- /starter/CollectionViewLayoutExample.xcodeproj/xcuserdata/fernando.moyaderivas.xcuserdatad/xcschemes/xcschememanagement.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | SchemeUserState 6 | 7 | CollectionViewLayoutExample.xcscheme_^#shared#^_ 8 | 9 | orderHint 10 | 0 11 | 12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /starter/CollectionViewLayoutExample/MainViewController.swift: -------------------------------------------------------------------------------- 1 | // 2 | // ViewController.swift 3 | // CollectionViewLayoutExample 4 | // 5 | // Created by Fernando Moya de Rivas on 05/04/2020. 6 | // Copyright © 2020 Fernando Moya de Rivas. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | 11 | class MainViewController: UICollectionViewController { 12 | 13 | private let numberOfSections = 4 14 | private let numberOfItemsInSection = [13, 10, 9, 16] 15 | private let cellIdentifier = "SpannableCollectionViewExampleCell" 16 | private let headerIdentifier = "SpannableCollectionViewExampleHeader" 17 | private let footerIdentifier = "SpannableCollectionViewExampleFooter" 18 | 19 | private let columnSpans = [[1, 1, 1, 1], [2, 2], [3, 1], [1, 2, 1]] 20 | 21 | init() { 22 | let layout = UICollectionViewFlowLayout() 23 | super.init(collectionViewLayout: layout) 24 | layout.headerReferenceSize = CGSize(width: view.bounds.size.width, height: 40) 25 | layout.footerReferenceSize = CGSize(width: view.bounds.size.width, height: 40) 26 | } 27 | 28 | required init?(coder: NSCoder) { 29 | fatalError("init(coder:) has not been implemented") 30 | } 31 | 32 | override func viewDidLoad() { 33 | super.viewDidLoad() 34 | 35 | collectionView.register(GridColletionViewCell.self, forCellWithReuseIdentifier: cellIdentifier) 36 | collectionView.register(GridSuplementaryView.self, forSupplementaryViewOfKind: UICollectionView.elementKindSectionHeader, withReuseIdentifier: headerIdentifier) 37 | collectionView.register(GridSuplementaryView.self, forSupplementaryViewOfKind: UICollectionView.elementKindSectionFooter, withReuseIdentifier: footerIdentifier) 38 | } 39 | 40 | private func colorForCell(at indexPath: IndexPath) -> UIColor { 41 | let colors: [UIColor] = [.blue, .brown, .green, .red] 42 | return colors[indexPath.row % colors.count] 43 | } 44 | 45 | } 46 | 47 | // MARK: UICollectionViewDataSource 48 | 49 | extension MainViewController { 50 | 51 | override func numberOfSections(in collectionView: UICollectionView) -> Int { 52 | return numberOfSections 53 | } 54 | 55 | override func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int { 56 | return numberOfItemsInSection[section] 57 | } 58 | 59 | override func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell { 60 | let cell = collectionView.dequeueReusableCell(withReuseIdentifier: cellIdentifier, for: indexPath) as! GridColletionViewCell 61 | cell.text = "(\(indexPath.section),\(indexPath.row))" 62 | cell.backgroundColor = colorForCell(at: indexPath) 63 | return cell 64 | } 65 | 66 | } 67 | 68 | // MARK: UICollectionViewDelegate 69 | 70 | extension MainViewController { 71 | 72 | override func collectionView(_ collectionView: UICollectionView, viewForSupplementaryElementOfKind kind: String, at indexPath: IndexPath) -> UICollectionReusableView { 73 | 74 | let identifier = kind == UICollectionView.elementKindSectionHeader ? headerIdentifier : footerIdentifier 75 | guard let view = collectionView.dequeueReusableSupplementaryView(ofKind: kind, withReuseIdentifier: identifier, for: indexPath) as? GridSuplementaryView else { fatalError("Couldn't dequeue UICollectionView header") } 76 | 77 | let title = kind == UICollectionView.elementKindSectionHeader ? "Header" : "Footer" 78 | 79 | view.title = title 80 | return view 81 | } 82 | 83 | } 84 | -------------------------------------------------------------------------------- /starter/CollectionViewLayoutExample/Support/AppDelegate.swift: -------------------------------------------------------------------------------- 1 | // 2 | // AppDelegate.swift 3 | // CollectionViewLayoutExample 4 | // 5 | // Created by Fernando Moya de Rivas on 05/04/2020. 6 | // Copyright © 2020 Fernando Moya de Rivas. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | 11 | @UIApplicationMain 12 | class AppDelegate: UIResponder, UIApplicationDelegate { 13 | 14 | func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool { 15 | // Override point for customization after application launch. 16 | return true 17 | } 18 | 19 | // MARK: UISceneSession Lifecycle 20 | 21 | func application(_ application: UIApplication, configurationForConnecting connectingSceneSession: UISceneSession, options: UIScene.ConnectionOptions) -> UISceneConfiguration { 22 | // Called when a new scene session is being created. 23 | // Use this method to select a configuration to create the new scene with. 24 | return UISceneConfiguration(name: "Default Configuration", sessionRole: connectingSceneSession.role) 25 | } 26 | 27 | } 28 | 29 | -------------------------------------------------------------------------------- /starter/CollectionViewLayoutExample/Support/Assets.xcassets/AppIcon.appiconset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "iphone", 5 | "scale" : "2x", 6 | "size" : "20x20" 7 | }, 8 | { 9 | "idiom" : "iphone", 10 | "scale" : "3x", 11 | "size" : "20x20" 12 | }, 13 | { 14 | "idiom" : "iphone", 15 | "scale" : "2x", 16 | "size" : "29x29" 17 | }, 18 | { 19 | "idiom" : "iphone", 20 | "scale" : "3x", 21 | "size" : "29x29" 22 | }, 23 | { 24 | "idiom" : "iphone", 25 | "scale" : "2x", 26 | "size" : "40x40" 27 | }, 28 | { 29 | "idiom" : "iphone", 30 | "scale" : "3x", 31 | "size" : "40x40" 32 | }, 33 | { 34 | "idiom" : "iphone", 35 | "scale" : "2x", 36 | "size" : "60x60" 37 | }, 38 | { 39 | "idiom" : "iphone", 40 | "scale" : "3x", 41 | "size" : "60x60" 42 | }, 43 | { 44 | "idiom" : "ipad", 45 | "scale" : "1x", 46 | "size" : "20x20" 47 | }, 48 | { 49 | "idiom" : "ipad", 50 | "scale" : "2x", 51 | "size" : "20x20" 52 | }, 53 | { 54 | "idiom" : "ipad", 55 | "scale" : "1x", 56 | "size" : "29x29" 57 | }, 58 | { 59 | "idiom" : "ipad", 60 | "scale" : "2x", 61 | "size" : "29x29" 62 | }, 63 | { 64 | "idiom" : "ipad", 65 | "scale" : "1x", 66 | "size" : "40x40" 67 | }, 68 | { 69 | "idiom" : "ipad", 70 | "scale" : "2x", 71 | "size" : "40x40" 72 | }, 73 | { 74 | "idiom" : "ipad", 75 | "scale" : "1x", 76 | "size" : "76x76" 77 | }, 78 | { 79 | "idiom" : "ipad", 80 | "scale" : "2x", 81 | "size" : "76x76" 82 | }, 83 | { 84 | "idiom" : "ipad", 85 | "scale" : "2x", 86 | "size" : "83.5x83.5" 87 | }, 88 | { 89 | "idiom" : "ios-marketing", 90 | "scale" : "1x", 91 | "size" : "1024x1024" 92 | } 93 | ], 94 | "info" : { 95 | "author" : "xcode", 96 | "version" : 1 97 | } 98 | } 99 | -------------------------------------------------------------------------------- /starter/CollectionViewLayoutExample/Support/Assets.xcassets/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "info" : { 3 | "author" : "xcode", 4 | "version" : 1 5 | } 6 | } 7 | -------------------------------------------------------------------------------- /starter/CollectionViewLayoutExample/Support/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 | -------------------------------------------------------------------------------- /starter/CollectionViewLayoutExample/Support/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 | $(PRODUCT_BUNDLE_PACKAGE_TYPE) 17 | CFBundleShortVersionString 18 | 1.0 19 | CFBundleVersion 20 | 1 21 | LSRequiresIPhoneOS 22 | 23 | UIApplicationSceneManifest 24 | 25 | UIApplicationSupportsMultipleScenes 26 | 27 | UISceneConfigurations 28 | 29 | UIWindowSceneSessionRoleApplication 30 | 31 | 32 | UISceneConfigurationName 33 | Default Configuration 34 | UISceneDelegateClassName 35 | $(PRODUCT_MODULE_NAME).SceneDelegate 36 | 37 | 38 | 39 | 40 | UILaunchStoryboardName 41 | LaunchScreen 42 | UIRequiredDeviceCapabilities 43 | 44 | armv7 45 | 46 | UISupportedInterfaceOrientations 47 | 48 | UIInterfaceOrientationPortrait 49 | UIInterfaceOrientationLandscapeLeft 50 | UIInterfaceOrientationLandscapeRight 51 | 52 | UISupportedInterfaceOrientations~ipad 53 | 54 | UIInterfaceOrientationPortrait 55 | UIInterfaceOrientationPortraitUpsideDown 56 | UIInterfaceOrientationLandscapeLeft 57 | UIInterfaceOrientationLandscapeRight 58 | 59 | 60 | 61 | -------------------------------------------------------------------------------- /starter/CollectionViewLayoutExample/Support/SceneDelegate.swift: -------------------------------------------------------------------------------- 1 | // 2 | // SceneDelegate.swift 3 | // CollectionViewLayoutExample 4 | // 5 | // Created by Fernando Moya de Rivas on 05/04/2020. 6 | // Copyright © 2020 Fernando Moya de Rivas. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | 11 | class SceneDelegate: UIResponder, UIWindowSceneDelegate { 12 | 13 | var window: UIWindow? 14 | 15 | func scene(_ scene: UIScene, willConnectTo session: UISceneSession, options connectionOptions: UIScene.ConnectionOptions) { 16 | 17 | if let windowScene = scene as? UIWindowScene { 18 | let window = UIWindow(windowScene: windowScene) 19 | window.rootViewController = MainViewController() 20 | self.window = window 21 | window.makeKeyAndVisible() 22 | } 23 | 24 | } 25 | 26 | } 27 | 28 | -------------------------------------------------------------------------------- /starter/CollectionViewLayoutExample/Views/GridColletionViewCell.swift: -------------------------------------------------------------------------------- 1 | // 2 | // MattrixColletionViewCell.swift 3 | // CollectionViewLayoutExample 4 | // 5 | // Created by Fernando Moya de Rivas on 13/04/2020. 6 | // Copyright © 2020 Fernando Moya de Rivas. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | 11 | class GridColletionViewCell: UICollectionViewCell { 12 | 13 | var text: String = "" { 14 | didSet { 15 | titlelLabel.text = text 16 | } 17 | } 18 | 19 | private var titlelLabel: UILabel = { 20 | let label = UILabel() 21 | label.textColor = .white 22 | label.font = .systemFont(ofSize: 11) 23 | label.numberOfLines = 0 24 | label.textAlignment = .left 25 | return label 26 | }() 27 | 28 | override func didMoveToWindow() { 29 | super.didMoveToWindow() 30 | if contentView.subviews.isEmpty { contentView.addSubview(titlelLabel) } 31 | } 32 | 33 | override func layoutSubviews() { 34 | super.layoutSubviews() 35 | titlelLabel.frame = contentView.bounds 36 | } 37 | 38 | } 39 | 40 | -------------------------------------------------------------------------------- /starter/CollectionViewLayoutExample/Views/GridSuplementaryView.swift: -------------------------------------------------------------------------------- 1 | // 2 | // SectionTitleView.swift 3 | // CollectionViewLayoutExample 4 | // 5 | // Created by Fernando Moya de Rivas on 05/04/2020. 6 | // Copyright © 2020 Fernando Moya de Rivas. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | 11 | class GridSuplementaryView: UICollectionReusableView { 12 | 13 | var title: String? { 14 | set { 15 | titleLabel.text = newValue 16 | } 17 | get { titleLabel.text } 18 | } 19 | 20 | private lazy var titleLabel: UILabel = { 21 | let label = UILabel() 22 | label.translatesAutoresizingMaskIntoConstraints = false 23 | label.textColor = .systemGray 24 | label.font = .systemFont(ofSize: 25, weight: .medium) 25 | return label 26 | }() 27 | 28 | override func didMoveToWindow() { 29 | super.didMoveToWindow() 30 | 31 | guard subviews.isEmpty else { return } 32 | 33 | addSubview(titleLabel) 34 | NSLayoutConstraint.activate([ 35 | titleLabel.centerYAnchor.constraint(equalTo: centerYAnchor), 36 | titleLabel.leadingAnchor.constraint(equalTo: leadingAnchor, constant: 16) 37 | ]) 38 | } 39 | 40 | } 41 | --------------------------------------------------------------------------------