├── Images ├── SCSectionBackground.png ├── SCSectionBackground_Example.png ├── SCSectionBackground_debugViewHierarchy.png ├── SCSectionBackground_small.png └── Screen Shot.png ├── LICENSE ├── README.md ├── SCSectionBackground.xcodeproj ├── project.pbxproj ├── project.xcworkspace │ ├── contents.xcworkspacedata │ └── xcuserdata │ │ ├── catherine.xcuserdatad │ │ └── UserInterfaceState.xcuserstate │ │ └── catherineschwartz.xcuserdatad │ │ └── UserInterfaceState.xcuserstate └── xcuserdata │ ├── catherine.xcuserdatad │ └── xcschemes │ │ ├── SCSectionBackground.xcscheme │ │ └── xcschememanagement.plist │ └── catherineschwartz.xcuserdatad │ └── xcschemes │ ├── SCSectionBackground.xcscheme │ └── xcschememanagement.plist ├── SCSectionBackground ├── AppDelegate.swift ├── Assets.xcassets │ ├── AppIcon.appiconset │ │ └── Contents.json │ ├── Contents.json │ └── background.imageset │ │ ├── Contents.json │ │ └── background.png ├── Base.lproj │ ├── LaunchScreen.storyboard │ └── Main.storyboard ├── ExampleFlowLayout.swift ├── ExampleViewController.swift ├── Extensions.swift ├── Info.plist ├── SectionBackgroundCollectionViewController.swift ├── SectionBackgroundFlowLayout.swift └── ViewController.swift ├── SCSectionBackgroundTests ├── Info.plist └── SCSectionBackgroundTests.swift └── SCSectionBackgroundUITests ├── Info.plist └── SCSectionBackgroundUITests.swift /Images/SCSectionBackground.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/strawberrycode/SCSectionBackground/81febf5a66a909c1bb2051d5ba401e3585f6edf4/Images/SCSectionBackground.png -------------------------------------------------------------------------------- /Images/SCSectionBackground_Example.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/strawberrycode/SCSectionBackground/81febf5a66a909c1bb2051d5ba401e3585f6edf4/Images/SCSectionBackground_Example.png -------------------------------------------------------------------------------- /Images/SCSectionBackground_debugViewHierarchy.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/strawberrycode/SCSectionBackground/81febf5a66a909c1bb2051d5ba401e3585f6edf4/Images/SCSectionBackground_debugViewHierarchy.png -------------------------------------------------------------------------------- /Images/SCSectionBackground_small.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/strawberrycode/SCSectionBackground/81febf5a66a909c1bb2051d5ba401e3585f6edf4/Images/SCSectionBackground_small.png -------------------------------------------------------------------------------- /Images/Screen Shot.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/strawberrycode/SCSectionBackground/81febf5a66a909c1bb2051d5ba401e3585f6edf4/Images/Screen Shot.png -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2015 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | 23 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # UICollectionView section background 2 | 3 | This project shows how to apply colour to background sections (or cells) on a `UICollectionView`. The code is written in Swift, and inspired by Eric [Chapman's article](http://www.ericjchapman.com/ios-changing-the-section-background-color-in-a-uicollectionview.html) (Objective-C [GitHub project](https://github.com/ericchapman/ios_decoration_view)). 4 | You can apply different colours according to the `NSIndexPath` of the cells. Here is an example of a `UICollectionView` 4 sections, 3 cells with green background on the even sections and 7 cells on a blue background on the odd ones. 5 | 6 | ![Section Background in UICollectionView](/Images/SCSectionBackground_small.png?raw=true "Section Background in UICollectionView") 7 | 8 | 9 | ## How does it work? 10 | The idea is to override `UICollectionViewLayoutAttributes` to add a color attribute. 11 | And then override `UICollectionReusableView` apply the color to the view background. Easy peasy :) 12 | 13 | ``` 14 | class SCSBCollectionViewLayoutAttributes : UICollectionViewLayoutAttributes { 15 | var color: UIColor = UIColor.whiteColor() 16 | 17 | override func copyWithZone(zone: NSZone) -> AnyObject { 18 | let newAttributes: SCSBCollectionViewLayoutAttributes = super.copyWithZone(zone) as! SCSBCollectionViewLayoutAttributes 19 | newAttributes.color = self.color.copyWithZone(zone) as! UIColor 20 | return newAttributes 21 | } 22 | } 23 | class SCSBCollectionReusableView : UICollectionReusableView { 24 | override func applyLayoutAttributes(layoutAttributes: UICollectionViewLayoutAttributes) { 25 | super.applyLayoutAttributes(layoutAttributes) 26 | let scLayoutAttributes = layoutAttributes as! SCSBCollectionViewLayoutAttributes self.backgroundColor = scLayoutAttributes.color 27 | } 28 | } 29 | ``` 30 | 31 | ## How to use it? 32 | All this happens in the `UICollectionViewFlowLayout` used on your `UIcollectionView`. Here is an example of `layoutAttributesForElementsInRect`: 33 | ``` 34 | // Create decoration attributes 35 | let decorationAttributes = SCSBCollectionViewLayoutAttributes(forDecorationViewOfKind: "sectionBackground", withIndexPath: attr.indexPath) 36 | // Set the color(s) 37 | if (attr.indexPath.section % 2 == 0) { 38 | decorationAttributes.color = UIColor.greenColor().colorWithAlphaComponent(0.5) 39 | } else { 40 | decorationAttributes.color = UIColor.blueColor().colorWithAlphaComponent(0.5) 41 | } 42 | ``` 43 | You will find all the details in the [SectionBackgroundFlowLayout.swift file](https://github.com/strawberrycode/SCSectionBackground/blob/master/SCSectionBackground/SectionBackgroundFlowLayout.swift) and if you want more details, please have a look at my the article I've written about it: [How to create a Section Background in a UICollectionView in Swift](http://bit.ly/1oQuC7I). 44 | 45 | ## Contact 46 | You can ping me on Twitter [@cath_schwz](https://twitter.com/cath_schwz), open an issue on GitHub or leave a comment on my [blog](http://bit.ly/1oQuC7I) :) 47 | -------------------------------------------------------------------------------- /SCSectionBackground.xcodeproj/project.pbxproj: -------------------------------------------------------------------------------- 1 | // !$*UTF8*$! 2 | { 3 | archiveVersion = 1; 4 | classes = { 5 | }; 6 | objectVersion = 46; 7 | objects = { 8 | 9 | /* Begin PBXBuildFile section */ 10 | AC7B23D81C6DFD7800504B38 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = AC7B23D71C6DFD7800504B38 /* AppDelegate.swift */; }; 11 | AC7B23DA1C6DFD7800504B38 /* ViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = AC7B23D91C6DFD7800504B38 /* ViewController.swift */; }; 12 | AC7B23DD1C6DFD7800504B38 /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = AC7B23DB1C6DFD7800504B38 /* Main.storyboard */; }; 13 | AC7B23DF1C6DFD7800504B38 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = AC7B23DE1C6DFD7800504B38 /* Assets.xcassets */; }; 14 | AC7B23E21C6DFD7800504B38 /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = AC7B23E01C6DFD7800504B38 /* LaunchScreen.storyboard */; }; 15 | AC7B23ED1C6DFD7800504B38 /* SCSectionBackgroundTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = AC7B23EC1C6DFD7800504B38 /* SCSectionBackgroundTests.swift */; }; 16 | AC7B23F81C6DFD7800504B38 /* SCSectionBackgroundUITests.swift in Sources */ = {isa = PBXBuildFile; fileRef = AC7B23F71C6DFD7800504B38 /* SCSectionBackgroundUITests.swift */; }; 17 | AC7B240A1C6DFFB000504B38 /* SectionBackgroundCollectionViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = AC7B24091C6DFFB000504B38 /* SectionBackgroundCollectionViewController.swift */; }; 18 | AC7B240C1C6DFFE100504B38 /* Extensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = AC7B240B1C6DFFE100504B38 /* Extensions.swift */; }; 19 | AC7B240E1C6DFFE800504B38 /* SectionBackgroundFlowLayout.swift in Sources */ = {isa = PBXBuildFile; fileRef = AC7B240D1C6DFFE800504B38 /* SectionBackgroundFlowLayout.swift */; }; 20 | AC7B24101C6E04C300504B38 /* ExampleViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = AC7B240F1C6E04C300504B38 /* ExampleViewController.swift */; }; 21 | C19932761C866FFC00CCC702 /* ExampleFlowLayout.swift in Sources */ = {isa = PBXBuildFile; fileRef = C19932751C866FFC00CCC702 /* ExampleFlowLayout.swift */; }; 22 | /* End PBXBuildFile section */ 23 | 24 | /* Begin PBXContainerItemProxy section */ 25 | AC7B23E91C6DFD7800504B38 /* PBXContainerItemProxy */ = { 26 | isa = PBXContainerItemProxy; 27 | containerPortal = AC7B23CC1C6DFD7800504B38 /* Project object */; 28 | proxyType = 1; 29 | remoteGlobalIDString = AC7B23D31C6DFD7800504B38; 30 | remoteInfo = SCSectionBackground; 31 | }; 32 | AC7B23F41C6DFD7800504B38 /* PBXContainerItemProxy */ = { 33 | isa = PBXContainerItemProxy; 34 | containerPortal = AC7B23CC1C6DFD7800504B38 /* Project object */; 35 | proxyType = 1; 36 | remoteGlobalIDString = AC7B23D31C6DFD7800504B38; 37 | remoteInfo = SCSectionBackground; 38 | }; 39 | /* End PBXContainerItemProxy section */ 40 | 41 | /* Begin PBXFileReference section */ 42 | AC7B23D41C6DFD7800504B38 /* SCSectionBackground.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = SCSectionBackground.app; sourceTree = BUILT_PRODUCTS_DIR; }; 43 | AC7B23D71C6DFD7800504B38 /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = ""; }; 44 | AC7B23D91C6DFD7800504B38 /* ViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ViewController.swift; sourceTree = ""; }; 45 | AC7B23DC1C6DFD7800504B38 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/Main.storyboard; sourceTree = ""; }; 46 | AC7B23DE1C6DFD7800504B38 /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = ""; }; 47 | AC7B23E11C6DFD7800504B38 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/LaunchScreen.storyboard; sourceTree = ""; }; 48 | AC7B23E31C6DFD7800504B38 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 49 | AC7B23E81C6DFD7800504B38 /* SCSectionBackgroundTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = SCSectionBackgroundTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; }; 50 | AC7B23EC1C6DFD7800504B38 /* SCSectionBackgroundTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SCSectionBackgroundTests.swift; sourceTree = ""; }; 51 | AC7B23EE1C6DFD7800504B38 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 52 | AC7B23F31C6DFD7800504B38 /* SCSectionBackgroundUITests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = SCSectionBackgroundUITests.xctest; sourceTree = BUILT_PRODUCTS_DIR; }; 53 | AC7B23F71C6DFD7800504B38 /* SCSectionBackgroundUITests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SCSectionBackgroundUITests.swift; sourceTree = ""; }; 54 | AC7B23F91C6DFD7800504B38 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 55 | AC7B24091C6DFFB000504B38 /* SectionBackgroundCollectionViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SectionBackgroundCollectionViewController.swift; sourceTree = ""; }; 56 | AC7B240B1C6DFFE100504B38 /* Extensions.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Extensions.swift; sourceTree = ""; }; 57 | AC7B240D1C6DFFE800504B38 /* SectionBackgroundFlowLayout.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SectionBackgroundFlowLayout.swift; sourceTree = ""; }; 58 | AC7B240F1C6E04C300504B38 /* ExampleViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ExampleViewController.swift; sourceTree = ""; }; 59 | C19932751C866FFC00CCC702 /* ExampleFlowLayout.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ExampleFlowLayout.swift; sourceTree = ""; }; 60 | /* End PBXFileReference section */ 61 | 62 | /* Begin PBXFrameworksBuildPhase section */ 63 | AC7B23D11C6DFD7800504B38 /* Frameworks */ = { 64 | isa = PBXFrameworksBuildPhase; 65 | buildActionMask = 2147483647; 66 | files = ( 67 | ); 68 | runOnlyForDeploymentPostprocessing = 0; 69 | }; 70 | AC7B23E51C6DFD7800504B38 /* Frameworks */ = { 71 | isa = PBXFrameworksBuildPhase; 72 | buildActionMask = 2147483647; 73 | files = ( 74 | ); 75 | runOnlyForDeploymentPostprocessing = 0; 76 | }; 77 | AC7B23F01C6DFD7800504B38 /* Frameworks */ = { 78 | isa = PBXFrameworksBuildPhase; 79 | buildActionMask = 2147483647; 80 | files = ( 81 | ); 82 | runOnlyForDeploymentPostprocessing = 0; 83 | }; 84 | /* End PBXFrameworksBuildPhase section */ 85 | 86 | /* Begin PBXGroup section */ 87 | AC7B23CB1C6DFD7800504B38 = { 88 | isa = PBXGroup; 89 | children = ( 90 | AC7B23D61C6DFD7800504B38 /* SCSectionBackground */, 91 | AC7B23EB1C6DFD7800504B38 /* SCSectionBackgroundTests */, 92 | AC7B23F61C6DFD7800504B38 /* SCSectionBackgroundUITests */, 93 | AC7B23D51C6DFD7800504B38 /* Products */, 94 | ); 95 | sourceTree = ""; 96 | }; 97 | AC7B23D51C6DFD7800504B38 /* Products */ = { 98 | isa = PBXGroup; 99 | children = ( 100 | AC7B23D41C6DFD7800504B38 /* SCSectionBackground.app */, 101 | AC7B23E81C6DFD7800504B38 /* SCSectionBackgroundTests.xctest */, 102 | AC7B23F31C6DFD7800504B38 /* SCSectionBackgroundUITests.xctest */, 103 | ); 104 | name = Products; 105 | sourceTree = ""; 106 | }; 107 | AC7B23D61C6DFD7800504B38 /* SCSectionBackground */ = { 108 | isa = PBXGroup; 109 | children = ( 110 | AC7B240B1C6DFFE100504B38 /* Extensions.swift */, 111 | AC7B23D71C6DFD7800504B38 /* AppDelegate.swift */, 112 | AC7B23D91C6DFD7800504B38 /* ViewController.swift */, 113 | AC7B23DB1C6DFD7800504B38 /* Main.storyboard */, 114 | AC7B23DE1C6DFD7800504B38 /* Assets.xcassets */, 115 | AC7B23E01C6DFD7800504B38 /* LaunchScreen.storyboard */, 116 | AC7B23E31C6DFD7800504B38 /* Info.plist */, 117 | AC7B24091C6DFFB000504B38 /* SectionBackgroundCollectionViewController.swift */, 118 | AC7B240D1C6DFFE800504B38 /* SectionBackgroundFlowLayout.swift */, 119 | AC7B240F1C6E04C300504B38 /* ExampleViewController.swift */, 120 | C19932751C866FFC00CCC702 /* ExampleFlowLayout.swift */, 121 | ); 122 | path = SCSectionBackground; 123 | sourceTree = ""; 124 | }; 125 | AC7B23EB1C6DFD7800504B38 /* SCSectionBackgroundTests */ = { 126 | isa = PBXGroup; 127 | children = ( 128 | AC7B23EC1C6DFD7800504B38 /* SCSectionBackgroundTests.swift */, 129 | AC7B23EE1C6DFD7800504B38 /* Info.plist */, 130 | ); 131 | path = SCSectionBackgroundTests; 132 | sourceTree = ""; 133 | }; 134 | AC7B23F61C6DFD7800504B38 /* SCSectionBackgroundUITests */ = { 135 | isa = PBXGroup; 136 | children = ( 137 | AC7B23F71C6DFD7800504B38 /* SCSectionBackgroundUITests.swift */, 138 | AC7B23F91C6DFD7800504B38 /* Info.plist */, 139 | ); 140 | path = SCSectionBackgroundUITests; 141 | sourceTree = ""; 142 | }; 143 | /* End PBXGroup section */ 144 | 145 | /* Begin PBXNativeTarget section */ 146 | AC7B23D31C6DFD7800504B38 /* SCSectionBackground */ = { 147 | isa = PBXNativeTarget; 148 | buildConfigurationList = AC7B23FC1C6DFD7800504B38 /* Build configuration list for PBXNativeTarget "SCSectionBackground" */; 149 | buildPhases = ( 150 | AC7B23D01C6DFD7800504B38 /* Sources */, 151 | AC7B23D11C6DFD7800504B38 /* Frameworks */, 152 | AC7B23D21C6DFD7800504B38 /* Resources */, 153 | ); 154 | buildRules = ( 155 | ); 156 | dependencies = ( 157 | ); 158 | name = SCSectionBackground; 159 | productName = SCSectionBackground; 160 | productReference = AC7B23D41C6DFD7800504B38 /* SCSectionBackground.app */; 161 | productType = "com.apple.product-type.application"; 162 | }; 163 | AC7B23E71C6DFD7800504B38 /* SCSectionBackgroundTests */ = { 164 | isa = PBXNativeTarget; 165 | buildConfigurationList = AC7B23FF1C6DFD7800504B38 /* Build configuration list for PBXNativeTarget "SCSectionBackgroundTests" */; 166 | buildPhases = ( 167 | AC7B23E41C6DFD7800504B38 /* Sources */, 168 | AC7B23E51C6DFD7800504B38 /* Frameworks */, 169 | AC7B23E61C6DFD7800504B38 /* Resources */, 170 | ); 171 | buildRules = ( 172 | ); 173 | dependencies = ( 174 | AC7B23EA1C6DFD7800504B38 /* PBXTargetDependency */, 175 | ); 176 | name = SCSectionBackgroundTests; 177 | productName = SCSectionBackgroundTests; 178 | productReference = AC7B23E81C6DFD7800504B38 /* SCSectionBackgroundTests.xctest */; 179 | productType = "com.apple.product-type.bundle.unit-test"; 180 | }; 181 | AC7B23F21C6DFD7800504B38 /* SCSectionBackgroundUITests */ = { 182 | isa = PBXNativeTarget; 183 | buildConfigurationList = AC7B24021C6DFD7800504B38 /* Build configuration list for PBXNativeTarget "SCSectionBackgroundUITests" */; 184 | buildPhases = ( 185 | AC7B23EF1C6DFD7800504B38 /* Sources */, 186 | AC7B23F01C6DFD7800504B38 /* Frameworks */, 187 | AC7B23F11C6DFD7800504B38 /* Resources */, 188 | ); 189 | buildRules = ( 190 | ); 191 | dependencies = ( 192 | AC7B23F51C6DFD7800504B38 /* PBXTargetDependency */, 193 | ); 194 | name = SCSectionBackgroundUITests; 195 | productName = SCSectionBackgroundUITests; 196 | productReference = AC7B23F31C6DFD7800504B38 /* SCSectionBackgroundUITests.xctest */; 197 | productType = "com.apple.product-type.bundle.ui-testing"; 198 | }; 199 | /* End PBXNativeTarget section */ 200 | 201 | /* Begin PBXProject section */ 202 | AC7B23CC1C6DFD7800504B38 /* Project object */ = { 203 | isa = PBXProject; 204 | attributes = { 205 | LastSwiftUpdateCheck = 0720; 206 | LastUpgradeCheck = 0720; 207 | ORGANIZATIONNAME = StrawberryCode; 208 | TargetAttributes = { 209 | AC7B23D31C6DFD7800504B38 = { 210 | CreatedOnToolsVersion = 7.2.1; 211 | }; 212 | AC7B23E71C6DFD7800504B38 = { 213 | CreatedOnToolsVersion = 7.2.1; 214 | TestTargetID = AC7B23D31C6DFD7800504B38; 215 | }; 216 | AC7B23F21C6DFD7800504B38 = { 217 | CreatedOnToolsVersion = 7.2.1; 218 | TestTargetID = AC7B23D31C6DFD7800504B38; 219 | }; 220 | }; 221 | }; 222 | buildConfigurationList = AC7B23CF1C6DFD7800504B38 /* Build configuration list for PBXProject "SCSectionBackground" */; 223 | compatibilityVersion = "Xcode 3.2"; 224 | developmentRegion = English; 225 | hasScannedForEncodings = 0; 226 | knownRegions = ( 227 | en, 228 | Base, 229 | ); 230 | mainGroup = AC7B23CB1C6DFD7800504B38; 231 | productRefGroup = AC7B23D51C6DFD7800504B38 /* Products */; 232 | projectDirPath = ""; 233 | projectRoot = ""; 234 | targets = ( 235 | AC7B23D31C6DFD7800504B38 /* SCSectionBackground */, 236 | AC7B23E71C6DFD7800504B38 /* SCSectionBackgroundTests */, 237 | AC7B23F21C6DFD7800504B38 /* SCSectionBackgroundUITests */, 238 | ); 239 | }; 240 | /* End PBXProject section */ 241 | 242 | /* Begin PBXResourcesBuildPhase section */ 243 | AC7B23D21C6DFD7800504B38 /* Resources */ = { 244 | isa = PBXResourcesBuildPhase; 245 | buildActionMask = 2147483647; 246 | files = ( 247 | AC7B23E21C6DFD7800504B38 /* LaunchScreen.storyboard in Resources */, 248 | AC7B23DF1C6DFD7800504B38 /* Assets.xcassets in Resources */, 249 | AC7B23DD1C6DFD7800504B38 /* Main.storyboard in Resources */, 250 | ); 251 | runOnlyForDeploymentPostprocessing = 0; 252 | }; 253 | AC7B23E61C6DFD7800504B38 /* Resources */ = { 254 | isa = PBXResourcesBuildPhase; 255 | buildActionMask = 2147483647; 256 | files = ( 257 | ); 258 | runOnlyForDeploymentPostprocessing = 0; 259 | }; 260 | AC7B23F11C6DFD7800504B38 /* Resources */ = { 261 | isa = PBXResourcesBuildPhase; 262 | buildActionMask = 2147483647; 263 | files = ( 264 | ); 265 | runOnlyForDeploymentPostprocessing = 0; 266 | }; 267 | /* End PBXResourcesBuildPhase section */ 268 | 269 | /* Begin PBXSourcesBuildPhase section */ 270 | AC7B23D01C6DFD7800504B38 /* Sources */ = { 271 | isa = PBXSourcesBuildPhase; 272 | buildActionMask = 2147483647; 273 | files = ( 274 | AC7B240E1C6DFFE800504B38 /* SectionBackgroundFlowLayout.swift in Sources */, 275 | AC7B23DA1C6DFD7800504B38 /* ViewController.swift in Sources */, 276 | AC7B240A1C6DFFB000504B38 /* SectionBackgroundCollectionViewController.swift in Sources */, 277 | AC7B23D81C6DFD7800504B38 /* AppDelegate.swift in Sources */, 278 | AC7B240C1C6DFFE100504B38 /* Extensions.swift in Sources */, 279 | C19932761C866FFC00CCC702 /* ExampleFlowLayout.swift in Sources */, 280 | AC7B24101C6E04C300504B38 /* ExampleViewController.swift in Sources */, 281 | ); 282 | runOnlyForDeploymentPostprocessing = 0; 283 | }; 284 | AC7B23E41C6DFD7800504B38 /* Sources */ = { 285 | isa = PBXSourcesBuildPhase; 286 | buildActionMask = 2147483647; 287 | files = ( 288 | AC7B23ED1C6DFD7800504B38 /* SCSectionBackgroundTests.swift in Sources */, 289 | ); 290 | runOnlyForDeploymentPostprocessing = 0; 291 | }; 292 | AC7B23EF1C6DFD7800504B38 /* Sources */ = { 293 | isa = PBXSourcesBuildPhase; 294 | buildActionMask = 2147483647; 295 | files = ( 296 | AC7B23F81C6DFD7800504B38 /* SCSectionBackgroundUITests.swift in Sources */, 297 | ); 298 | runOnlyForDeploymentPostprocessing = 0; 299 | }; 300 | /* End PBXSourcesBuildPhase section */ 301 | 302 | /* Begin PBXTargetDependency section */ 303 | AC7B23EA1C6DFD7800504B38 /* PBXTargetDependency */ = { 304 | isa = PBXTargetDependency; 305 | target = AC7B23D31C6DFD7800504B38 /* SCSectionBackground */; 306 | targetProxy = AC7B23E91C6DFD7800504B38 /* PBXContainerItemProxy */; 307 | }; 308 | AC7B23F51C6DFD7800504B38 /* PBXTargetDependency */ = { 309 | isa = PBXTargetDependency; 310 | target = AC7B23D31C6DFD7800504B38 /* SCSectionBackground */; 311 | targetProxy = AC7B23F41C6DFD7800504B38 /* PBXContainerItemProxy */; 312 | }; 313 | /* End PBXTargetDependency section */ 314 | 315 | /* Begin PBXVariantGroup section */ 316 | AC7B23DB1C6DFD7800504B38 /* Main.storyboard */ = { 317 | isa = PBXVariantGroup; 318 | children = ( 319 | AC7B23DC1C6DFD7800504B38 /* Base */, 320 | ); 321 | name = Main.storyboard; 322 | sourceTree = ""; 323 | }; 324 | AC7B23E01C6DFD7800504B38 /* LaunchScreen.storyboard */ = { 325 | isa = PBXVariantGroup; 326 | children = ( 327 | AC7B23E11C6DFD7800504B38 /* Base */, 328 | ); 329 | name = LaunchScreen.storyboard; 330 | sourceTree = ""; 331 | }; 332 | /* End PBXVariantGroup section */ 333 | 334 | /* Begin XCBuildConfiguration section */ 335 | AC7B23FA1C6DFD7800504B38 /* Debug */ = { 336 | isa = XCBuildConfiguration; 337 | buildSettings = { 338 | ALWAYS_SEARCH_USER_PATHS = NO; 339 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; 340 | CLANG_CXX_LIBRARY = "libc++"; 341 | CLANG_ENABLE_MODULES = YES; 342 | CLANG_ENABLE_OBJC_ARC = YES; 343 | CLANG_WARN_BOOL_CONVERSION = YES; 344 | CLANG_WARN_CONSTANT_CONVERSION = YES; 345 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 346 | CLANG_WARN_EMPTY_BODY = YES; 347 | CLANG_WARN_ENUM_CONVERSION = YES; 348 | CLANG_WARN_INT_CONVERSION = YES; 349 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 350 | CLANG_WARN_UNREACHABLE_CODE = YES; 351 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 352 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; 353 | COPY_PHASE_STRIP = NO; 354 | DEBUG_INFORMATION_FORMAT = dwarf; 355 | ENABLE_STRICT_OBJC_MSGSEND = YES; 356 | ENABLE_TESTABILITY = YES; 357 | GCC_C_LANGUAGE_STANDARD = gnu99; 358 | GCC_DYNAMIC_NO_PIC = NO; 359 | GCC_NO_COMMON_BLOCKS = YES; 360 | GCC_OPTIMIZATION_LEVEL = 0; 361 | GCC_PREPROCESSOR_DEFINITIONS = ( 362 | "DEBUG=1", 363 | "$(inherited)", 364 | ); 365 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 366 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 367 | GCC_WARN_UNDECLARED_SELECTOR = YES; 368 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 369 | GCC_WARN_UNUSED_FUNCTION = YES; 370 | GCC_WARN_UNUSED_VARIABLE = YES; 371 | IPHONEOS_DEPLOYMENT_TARGET = 9.2; 372 | MTL_ENABLE_DEBUG_INFO = YES; 373 | ONLY_ACTIVE_ARCH = YES; 374 | SDKROOT = iphoneos; 375 | SWIFT_OPTIMIZATION_LEVEL = "-Onone"; 376 | TARGETED_DEVICE_FAMILY = "1,2"; 377 | }; 378 | name = Debug; 379 | }; 380 | AC7B23FB1C6DFD7800504B38 /* Release */ = { 381 | isa = XCBuildConfiguration; 382 | buildSettings = { 383 | ALWAYS_SEARCH_USER_PATHS = NO; 384 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; 385 | CLANG_CXX_LIBRARY = "libc++"; 386 | CLANG_ENABLE_MODULES = YES; 387 | CLANG_ENABLE_OBJC_ARC = YES; 388 | CLANG_WARN_BOOL_CONVERSION = YES; 389 | CLANG_WARN_CONSTANT_CONVERSION = YES; 390 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 391 | CLANG_WARN_EMPTY_BODY = YES; 392 | CLANG_WARN_ENUM_CONVERSION = YES; 393 | CLANG_WARN_INT_CONVERSION = YES; 394 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 395 | CLANG_WARN_UNREACHABLE_CODE = YES; 396 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 397 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; 398 | COPY_PHASE_STRIP = NO; 399 | DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; 400 | ENABLE_NS_ASSERTIONS = NO; 401 | ENABLE_STRICT_OBJC_MSGSEND = YES; 402 | GCC_C_LANGUAGE_STANDARD = gnu99; 403 | GCC_NO_COMMON_BLOCKS = YES; 404 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 405 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 406 | GCC_WARN_UNDECLARED_SELECTOR = YES; 407 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 408 | GCC_WARN_UNUSED_FUNCTION = YES; 409 | GCC_WARN_UNUSED_VARIABLE = YES; 410 | IPHONEOS_DEPLOYMENT_TARGET = 9.2; 411 | MTL_ENABLE_DEBUG_INFO = NO; 412 | SDKROOT = iphoneos; 413 | TARGETED_DEVICE_FAMILY = "1,2"; 414 | VALIDATE_PRODUCT = YES; 415 | }; 416 | name = Release; 417 | }; 418 | AC7B23FD1C6DFD7800504B38 /* Debug */ = { 419 | isa = XCBuildConfiguration; 420 | buildSettings = { 421 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 422 | INFOPLIST_FILE = SCSectionBackground/Info.plist; 423 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; 424 | PRODUCT_BUNDLE_IDENTIFIER = com.strawberrycode.SCSectionBackground; 425 | PRODUCT_NAME = "$(TARGET_NAME)"; 426 | TARGETED_DEVICE_FAMILY = 1; 427 | }; 428 | name = Debug; 429 | }; 430 | AC7B23FE1C6DFD7800504B38 /* Release */ = { 431 | isa = XCBuildConfiguration; 432 | buildSettings = { 433 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 434 | INFOPLIST_FILE = SCSectionBackground/Info.plist; 435 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; 436 | PRODUCT_BUNDLE_IDENTIFIER = com.strawberrycode.SCSectionBackground; 437 | PRODUCT_NAME = "$(TARGET_NAME)"; 438 | TARGETED_DEVICE_FAMILY = 1; 439 | }; 440 | name = Release; 441 | }; 442 | AC7B24001C6DFD7800504B38 /* Debug */ = { 443 | isa = XCBuildConfiguration; 444 | buildSettings = { 445 | BUNDLE_LOADER = "$(TEST_HOST)"; 446 | INFOPLIST_FILE = SCSectionBackgroundTests/Info.plist; 447 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; 448 | PRODUCT_BUNDLE_IDENTIFIER = com.strawberrycode.SCSectionBackgroundTests; 449 | PRODUCT_NAME = "$(TARGET_NAME)"; 450 | TEST_HOST = "$(BUILT_PRODUCTS_DIR)/SCSectionBackground.app/SCSectionBackground"; 451 | }; 452 | name = Debug; 453 | }; 454 | AC7B24011C6DFD7800504B38 /* Release */ = { 455 | isa = XCBuildConfiguration; 456 | buildSettings = { 457 | BUNDLE_LOADER = "$(TEST_HOST)"; 458 | INFOPLIST_FILE = SCSectionBackgroundTests/Info.plist; 459 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; 460 | PRODUCT_BUNDLE_IDENTIFIER = com.strawberrycode.SCSectionBackgroundTests; 461 | PRODUCT_NAME = "$(TARGET_NAME)"; 462 | TEST_HOST = "$(BUILT_PRODUCTS_DIR)/SCSectionBackground.app/SCSectionBackground"; 463 | }; 464 | name = Release; 465 | }; 466 | AC7B24031C6DFD7800504B38 /* Debug */ = { 467 | isa = XCBuildConfiguration; 468 | buildSettings = { 469 | INFOPLIST_FILE = SCSectionBackgroundUITests/Info.plist; 470 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; 471 | PRODUCT_BUNDLE_IDENTIFIER = com.strawberrycode.SCSectionBackgroundUITests; 472 | PRODUCT_NAME = "$(TARGET_NAME)"; 473 | TEST_TARGET_NAME = SCSectionBackground; 474 | USES_XCTRUNNER = YES; 475 | }; 476 | name = Debug; 477 | }; 478 | AC7B24041C6DFD7800504B38 /* Release */ = { 479 | isa = XCBuildConfiguration; 480 | buildSettings = { 481 | INFOPLIST_FILE = SCSectionBackgroundUITests/Info.plist; 482 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; 483 | PRODUCT_BUNDLE_IDENTIFIER = com.strawberrycode.SCSectionBackgroundUITests; 484 | PRODUCT_NAME = "$(TARGET_NAME)"; 485 | TEST_TARGET_NAME = SCSectionBackground; 486 | USES_XCTRUNNER = YES; 487 | }; 488 | name = Release; 489 | }; 490 | /* End XCBuildConfiguration section */ 491 | 492 | /* Begin XCConfigurationList section */ 493 | AC7B23CF1C6DFD7800504B38 /* Build configuration list for PBXProject "SCSectionBackground" */ = { 494 | isa = XCConfigurationList; 495 | buildConfigurations = ( 496 | AC7B23FA1C6DFD7800504B38 /* Debug */, 497 | AC7B23FB1C6DFD7800504B38 /* Release */, 498 | ); 499 | defaultConfigurationIsVisible = 0; 500 | defaultConfigurationName = Release; 501 | }; 502 | AC7B23FC1C6DFD7800504B38 /* Build configuration list for PBXNativeTarget "SCSectionBackground" */ = { 503 | isa = XCConfigurationList; 504 | buildConfigurations = ( 505 | AC7B23FD1C6DFD7800504B38 /* Debug */, 506 | AC7B23FE1C6DFD7800504B38 /* Release */, 507 | ); 508 | defaultConfigurationIsVisible = 0; 509 | defaultConfigurationName = Release; 510 | }; 511 | AC7B23FF1C6DFD7800504B38 /* Build configuration list for PBXNativeTarget "SCSectionBackgroundTests" */ = { 512 | isa = XCConfigurationList; 513 | buildConfigurations = ( 514 | AC7B24001C6DFD7800504B38 /* Debug */, 515 | AC7B24011C6DFD7800504B38 /* Release */, 516 | ); 517 | defaultConfigurationIsVisible = 0; 518 | defaultConfigurationName = Release; 519 | }; 520 | AC7B24021C6DFD7800504B38 /* Build configuration list for PBXNativeTarget "SCSectionBackgroundUITests" */ = { 521 | isa = XCConfigurationList; 522 | buildConfigurations = ( 523 | AC7B24031C6DFD7800504B38 /* Debug */, 524 | AC7B24041C6DFD7800504B38 /* Release */, 525 | ); 526 | defaultConfigurationIsVisible = 0; 527 | defaultConfigurationName = Release; 528 | }; 529 | /* End XCConfigurationList section */ 530 | }; 531 | rootObject = AC7B23CC1C6DFD7800504B38 /* Project object */; 532 | } 533 | -------------------------------------------------------------------------------- /SCSectionBackground.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /SCSectionBackground.xcodeproj/project.xcworkspace/xcuserdata/catherine.xcuserdatad/UserInterfaceState.xcuserstate: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/strawberrycode/SCSectionBackground/81febf5a66a909c1bb2051d5ba401e3585f6edf4/SCSectionBackground.xcodeproj/project.xcworkspace/xcuserdata/catherine.xcuserdatad/UserInterfaceState.xcuserstate -------------------------------------------------------------------------------- /SCSectionBackground.xcodeproj/project.xcworkspace/xcuserdata/catherineschwartz.xcuserdatad/UserInterfaceState.xcuserstate: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/strawberrycode/SCSectionBackground/81febf5a66a909c1bb2051d5ba401e3585f6edf4/SCSectionBackground.xcodeproj/project.xcworkspace/xcuserdata/catherineschwartz.xcuserdatad/UserInterfaceState.xcuserstate -------------------------------------------------------------------------------- /SCSectionBackground.xcodeproj/xcuserdata/catherine.xcuserdatad/xcschemes/SCSectionBackground.xcscheme: -------------------------------------------------------------------------------- 1 | 2 | 5 | 8 | 9 | 15 | 21 | 22 | 23 | 24 | 25 | 30 | 31 | 33 | 39 | 40 | 41 | 43 | 49 | 50 | 51 | 52 | 53 | 59 | 60 | 61 | 62 | 63 | 64 | 74 | 76 | 82 | 83 | 84 | 85 | 86 | 87 | 93 | 95 | 101 | 102 | 103 | 104 | 106 | 107 | 110 | 111 | 112 | -------------------------------------------------------------------------------- /SCSectionBackground.xcodeproj/xcuserdata/catherine.xcuserdatad/xcschemes/xcschememanagement.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | SchemeUserState 6 | 7 | SCSectionBackground.xcscheme 8 | 9 | orderHint 10 | 0 11 | 12 | 13 | SuppressBuildableAutocreation 14 | 15 | AC7B23D31C6DFD7800504B38 16 | 17 | primary 18 | 19 | 20 | AC7B23E71C6DFD7800504B38 21 | 22 | primary 23 | 24 | 25 | AC7B23F21C6DFD7800504B38 26 | 27 | primary 28 | 29 | 30 | 31 | 32 | 33 | -------------------------------------------------------------------------------- /SCSectionBackground.xcodeproj/xcuserdata/catherineschwartz.xcuserdatad/xcschemes/SCSectionBackground.xcscheme: -------------------------------------------------------------------------------- 1 | 2 | 5 | 8 | 9 | 15 | 21 | 22 | 23 | 24 | 25 | 30 | 31 | 33 | 39 | 40 | 41 | 43 | 49 | 50 | 51 | 52 | 53 | 59 | 60 | 61 | 62 | 63 | 64 | 74 | 76 | 82 | 83 | 84 | 85 | 86 | 87 | 93 | 95 | 101 | 102 | 103 | 104 | 106 | 107 | 110 | 111 | 112 | -------------------------------------------------------------------------------- /SCSectionBackground.xcodeproj/xcuserdata/catherineschwartz.xcuserdatad/xcschemes/xcschememanagement.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | SchemeUserState 6 | 7 | SCSectionBackground.xcscheme 8 | 9 | orderHint 10 | 0 11 | 12 | 13 | SuppressBuildableAutocreation 14 | 15 | AC7B23D31C6DFD7800504B38 16 | 17 | primary 18 | 19 | 20 | AC7B23E71C6DFD7800504B38 21 | 22 | primary 23 | 24 | 25 | AC7B23F21C6DFD7800504B38 26 | 27 | primary 28 | 29 | 30 | 31 | 32 | 33 | -------------------------------------------------------------------------------- /SCSectionBackground/AppDelegate.swift: -------------------------------------------------------------------------------- 1 | // 2 | // AppDelegate.swift 3 | // SCSectionBackground 4 | // 5 | // Created by Catherine Schwartz on 12/02/2016. 6 | // Copyright © 2016 StrawberryCode. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | 11 | @UIApplicationMain 12 | class AppDelegate: UIResponder, UIApplicationDelegate { 13 | 14 | var window: UIWindow? 15 | 16 | 17 | func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool { 18 | // Override point for customization after application launch. 19 | return true 20 | } 21 | 22 | func applicationWillResignActive(application: UIApplication) { 23 | // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state. 24 | // Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game. 25 | } 26 | 27 | func applicationDidEnterBackground(application: UIApplication) { 28 | // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later. 29 | // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits. 30 | } 31 | 32 | func applicationWillEnterForeground(application: UIApplication) { 33 | // Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background. 34 | } 35 | 36 | func applicationDidBecomeActive(application: UIApplication) { 37 | // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface. 38 | } 39 | 40 | func applicationWillTerminate(application: UIApplication) { 41 | // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:. 42 | } 43 | 44 | 45 | } 46 | 47 | -------------------------------------------------------------------------------- /SCSectionBackground/Assets.xcassets/AppIcon.appiconset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "iphone", 5 | "size" : "29x29", 6 | "scale" : "2x" 7 | }, 8 | { 9 | "idiom" : "iphone", 10 | "size" : "29x29", 11 | "scale" : "3x" 12 | }, 13 | { 14 | "idiom" : "iphone", 15 | "size" : "40x40", 16 | "scale" : "2x" 17 | }, 18 | { 19 | "idiom" : "iphone", 20 | "size" : "40x40", 21 | "scale" : "3x" 22 | }, 23 | { 24 | "idiom" : "iphone", 25 | "size" : "60x60", 26 | "scale" : "2x" 27 | }, 28 | { 29 | "idiom" : "iphone", 30 | "size" : "60x60", 31 | "scale" : "3x" 32 | }, 33 | { 34 | "idiom" : "ipad", 35 | "size" : "29x29", 36 | "scale" : "1x" 37 | }, 38 | { 39 | "idiom" : "ipad", 40 | "size" : "29x29", 41 | "scale" : "2x" 42 | }, 43 | { 44 | "idiom" : "ipad", 45 | "size" : "40x40", 46 | "scale" : "1x" 47 | }, 48 | { 49 | "idiom" : "ipad", 50 | "size" : "40x40", 51 | "scale" : "2x" 52 | }, 53 | { 54 | "idiom" : "ipad", 55 | "size" : "76x76", 56 | "scale" : "1x" 57 | }, 58 | { 59 | "idiom" : "ipad", 60 | "size" : "76x76", 61 | "scale" : "2x" 62 | }, 63 | { 64 | "idiom" : "ipad", 65 | "size" : "83.5x83.5", 66 | "scale" : "2x" 67 | } 68 | ], 69 | "info" : { 70 | "version" : 1, 71 | "author" : "xcode" 72 | } 73 | } -------------------------------------------------------------------------------- /SCSectionBackground/Assets.xcassets/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "info" : { 3 | "version" : 1, 4 | "author" : "xcode" 5 | } 6 | } -------------------------------------------------------------------------------- /SCSectionBackground/Assets.xcassets/background.imageset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "universal", 5 | "filename" : "background.png", 6 | "scale" : "1x" 7 | }, 8 | { 9 | "idiom" : "universal", 10 | "scale" : "2x" 11 | }, 12 | { 13 | "idiom" : "universal", 14 | "scale" : "3x" 15 | } 16 | ], 17 | "info" : { 18 | "version" : 1, 19 | "author" : "xcode" 20 | } 21 | } -------------------------------------------------------------------------------- /SCSectionBackground/Assets.xcassets/background.imageset/background.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/strawberrycode/SCSectionBackground/81febf5a66a909c1bb2051d5ba401e3585f6edf4/SCSectionBackground/Assets.xcassets/background.imageset/background.png -------------------------------------------------------------------------------- /SCSectionBackground/Base.lproj/LaunchScreen.storyboard: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | -------------------------------------------------------------------------------- /SCSectionBackground/Base.lproj/Main.storyboard: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 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 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | 119 | 120 | 121 | 122 | 123 | 124 | 125 | 126 | 127 | 128 | 129 | 130 | 131 | 132 | 133 | 134 | 135 | 136 | 137 | 138 | 139 | 140 | 141 | 142 | 143 | 144 | 145 | 146 | 147 | 148 | 149 | 150 | 151 | 152 | 153 | 154 | 155 | 156 | 157 | 158 | 159 | 160 | 161 | 162 | 163 | 164 | 165 | 166 | 167 | 168 | 169 | 170 | 171 | 172 | 173 | 174 | 175 | 176 | 177 | 178 | 179 | 180 | 181 | 182 | 183 | 184 | 185 | 186 | 187 | 188 | 189 | 190 | -------------------------------------------------------------------------------- /SCSectionBackground/ExampleFlowLayout.swift: -------------------------------------------------------------------------------- 1 | // 2 | // ExampleFlowLayout.swift 3 | // SCSectionBackground 4 | // 5 | // Created by Catherine Schwartz on 02/03/2016. 6 | // Copyright © 2016 StrawberryCode. All rights reserved. 7 | // 8 | 9 | // 10 | // ExampleFlowLayout.swift 11 | // SCSectionBackground 12 | // 13 | // Created by Catherine Schwartz on 12/02/2016. 14 | // Copyright © 2016 StrawberryCode. All rights reserved. 15 | // 16 | 17 | import UIKit 18 | 19 | class ExampleFlowLayout: UICollectionViewFlowLayout { 20 | 21 | // MARK: prepareLayout 22 | 23 | override func prepareLayout() { 24 | super.prepareLayout() 25 | 26 | minimumLineSpacing = 8.0 27 | minimumInteritemSpacing = 8.0 28 | sectionInset = UIEdgeInsetsMake(8, 8, 8, 8) 29 | 30 | let width = (UIScreen.mainScreen().bounds.width / 3) - 2 * 8.0 31 | itemSize = CGSizeMake(width, 100) 32 | 33 | registerClass(SCSBCollectionReusableView.self, forDecorationViewOfKind: "sectionBackground") 34 | } 35 | 36 | // MARK: layoutAttributesForElementsInRect 37 | override func layoutAttributesForElementsInRect(rect: CGRect) -> [UICollectionViewLayoutAttributes]? { 38 | let attributes = super.layoutAttributesForElementsInRect(rect) 39 | var allAttributes = [UICollectionViewLayoutAttributes]() 40 | 41 | if let attributes = attributes { 42 | 43 | for attr in attributes { 44 | // Look for the first item in a row 45 | // You can also calculate it by item (remove the second check in the if below and change the tmpWidth and frame origin 46 | if (attr.representedElementCategory == UICollectionElementCategory.Cell && attr.frame.origin.x == self.sectionInset.left) { 47 | 48 | // Create decoration attributes 49 | let decorationAttributes = SCSBCollectionViewLayoutAttributes(forDecorationViewOfKind: "sectionBackground", withIndexPath: attr.indexPath) 50 | // Set the color(s) 51 | if (attr.indexPath.section % 2 == 0) { 52 | decorationAttributes.color = UIColor.clearColor() 53 | } else { 54 | decorationAttributes.color = UIColor.whiteColor().colorWithAlphaComponent(0.9) 55 | } 56 | 57 | // Make the decoration view span the entire row 58 | let tmpWidth = self.collectionView!.contentSize.width 59 | let tmpHeight = self.itemSize.height + self.minimumLineSpacing + self.sectionInset.top / 2 + self.sectionInset.bottom / 2 // or attributes.frame.size.height instead of itemSize.height if dynamic or recalculated 60 | decorationAttributes.frame = CGRectMake(0, attr.frame.origin.y - self.sectionInset.top, tmpWidth, tmpHeight) 61 | 62 | // Set the zIndex to be behind the item 63 | decorationAttributes.zIndex = attr.zIndex - 1 64 | 65 | // Add the attribute to the list 66 | allAttributes.append(decorationAttributes) 67 | } 68 | } 69 | // Combine the items and decorations arrays 70 | allAttributes.appendContentsOf(attributes) 71 | } 72 | 73 | return allAttributes 74 | } 75 | } 76 | -------------------------------------------------------------------------------- /SCSectionBackground/ExampleViewController.swift: -------------------------------------------------------------------------------- 1 | // 2 | // ExampleViewController.swift 3 | // SCSectionBackground 4 | // 5 | // Created by Catherine Schwartz on 12/02/2016. 6 | // Copyright © 2016 StrawberryCode. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | 11 | private let reuseIdentifier = "Cell" 12 | private let reuseIdentifierHeader = "Header" 13 | 14 | class ExampleViewController: UIViewController, UICollectionViewDataSource, UICollectionViewDelegate { 15 | 16 | @IBOutlet var collectionView: UICollectionView! 17 | 18 | 19 | override func viewDidLoad() { 20 | super.viewDidLoad() 21 | 22 | // Do any additional setup after loading the view. 23 | 24 | // Register cell classes 25 | self.collectionView!.registerClass(UICollectionViewCell.self, forCellWithReuseIdentifier: reuseIdentifier) 26 | self.collectionView!.registerClass(UICollectionReusableView.self, forSupplementaryViewOfKind: UICollectionElementKindSectionHeader, withReuseIdentifier: reuseIdentifierHeader) 27 | } 28 | 29 | override func didReceiveMemoryWarning() { 30 | super.didReceiveMemoryWarning() 31 | // Dispose of any resources that can be recreated. 32 | } 33 | 34 | override func viewDidAppear(animated: Bool) { 35 | super.viewDidAppear(animated) 36 | 37 | collectionView?.collectionViewLayout.invalidateLayout() 38 | } 39 | 40 | /* 41 | // MARK: - Navigation 42 | 43 | // In a storyboard-based application, you will often want to do a little preparation before navigation 44 | override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) { 45 | // Get the new view controller using segue.destinationViewController. 46 | // Pass the selected object to the new view controller. 47 | } 48 | */ 49 | 50 | func numberOfSectionsInCollectionView(collectionView: UICollectionView) -> Int { 51 | return 2 52 | } 53 | 54 | 55 | func collectionView(collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int { 56 | if (section % 2 == 0) { 57 | return 6 58 | } 59 | return 12 60 | } 61 | 62 | 63 | func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell { 64 | let cell = collectionView.dequeueReusableCellWithReuseIdentifier(reuseIdentifier, forIndexPath: indexPath) 65 | 66 | // Configure the cell 67 | cell.backgroundColor = UIColor.whiteColor() 68 | cell.setBorder(UIColor.grayColor().colorWithAlphaComponent(0.5)) 69 | return cell 70 | } 71 | 72 | 73 | func collectionView(collectionView: UICollectionView, viewForSupplementaryElementOfKind kind: String, atIndexPath indexPath: NSIndexPath) -> UICollectionReusableView { 74 | 75 | if (kind == UICollectionElementKindSectionHeader) { 76 | let view = collectionView.dequeueReusableSupplementaryViewOfKind(kind, withReuseIdentifier: reuseIdentifierHeader, forIndexPath: indexPath) 77 | 78 | view.backgroundColor = UIColor(white: 1, alpha: 0.6) 79 | return view 80 | } 81 | 82 | return UICollectionReusableView() 83 | } 84 | 85 | 86 | } 87 | -------------------------------------------------------------------------------- /SCSectionBackground/Extensions.swift: -------------------------------------------------------------------------------- 1 | // 2 | // Extensions.swift 3 | // SCSectionBackground 4 | // 5 | // Created by Catherine Schwartz on 12/02/2016. 6 | // Copyright © 2016 StrawberryCode. All rights reserved. 7 | // 8 | 9 | import Foundation 10 | import UIKit 11 | 12 | extension UIView { 13 | 14 | func setBorder(color: UIColor, width: CGFloat = 1.0) { 15 | 16 | self.layer.borderColor = color.CGColor 17 | self.layer.borderWidth = width 18 | } 19 | 20 | } -------------------------------------------------------------------------------- /SCSectionBackground/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleExecutable 8 | $(EXECUTABLE_NAME) 9 | CFBundleIdentifier 10 | $(PRODUCT_BUNDLE_IDENTIFIER) 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundleName 14 | $(PRODUCT_NAME) 15 | CFBundlePackageType 16 | APPL 17 | CFBundleShortVersionString 18 | 1.0 19 | CFBundleSignature 20 | ???? 21 | CFBundleVersion 22 | 1 23 | LSRequiresIPhoneOS 24 | 25 | UILaunchStoryboardName 26 | LaunchScreen 27 | UIMainStoryboardFile 28 | Main 29 | UIRequiredDeviceCapabilities 30 | 31 | armv7 32 | 33 | UISupportedInterfaceOrientations 34 | 35 | UIInterfaceOrientationPortrait 36 | 37 | UISupportedInterfaceOrientations~ipad 38 | 39 | UIInterfaceOrientationPortrait 40 | UIInterfaceOrientationPortraitUpsideDown 41 | UIInterfaceOrientationLandscapeLeft 42 | UIInterfaceOrientationLandscapeRight 43 | 44 | 45 | 46 | -------------------------------------------------------------------------------- /SCSectionBackground/SectionBackgroundCollectionViewController.swift: -------------------------------------------------------------------------------- 1 | // 2 | // SectionBackgroundCollectionViewController.swift 3 | // SCSectionBackground 4 | // 5 | // Created by Catherine Schwartz on 12/02/2016. 6 | // Copyright © 2016 StrawberryCode. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | 11 | private let reuseIdentifier = "Cell" 12 | 13 | class SectionBackgroundCollectionViewController: UICollectionViewController { 14 | 15 | override func viewDidLoad() { 16 | super.viewDidLoad() 17 | 18 | // Uncomment the following line to preserve selection between presentations 19 | // self.clearsSelectionOnViewWillAppear = false 20 | 21 | // Register cell classes 22 | self.collectionView!.registerClass(UICollectionViewCell.self, forCellWithReuseIdentifier: reuseIdentifier) 23 | 24 | // Do any additional setup after loading the view. 25 | self.collectionView?.backgroundColor = UIColor.whiteColor() // white for the example with transparency -- UIColor.clearColor() 26 | } 27 | 28 | override func didReceiveMemoryWarning() { 29 | super.didReceiveMemoryWarning() 30 | // Dispose of any resources that can be recreated. 31 | } 32 | 33 | override func viewDidAppear(animated: Bool) { 34 | super.viewDidAppear(animated) 35 | 36 | collectionView?.collectionViewLayout.invalidateLayout() 37 | } 38 | 39 | // MARK: UICollectionViewDataSource 40 | 41 | override func numberOfSectionsInCollectionView(collectionView: UICollectionView) -> Int { 42 | return 4 43 | } 44 | 45 | 46 | override func collectionView(collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int { 47 | if (section % 2 == 0) { 48 | return 3 49 | } 50 | return 7 51 | } 52 | 53 | override func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell { 54 | let cell = collectionView.dequeueReusableCellWithReuseIdentifier(reuseIdentifier, forIndexPath: indexPath) 55 | 56 | // Configure the cell 57 | cell.backgroundColor = UIColor(white: 0.9, alpha: 1) 58 | cell.setBorder(UIColor.redColor()) 59 | 60 | return cell 61 | } 62 | 63 | } 64 | -------------------------------------------------------------------------------- /SCSectionBackground/SectionBackgroundFlowLayout.swift: -------------------------------------------------------------------------------- 1 | // 2 | // SectionBackgroundFlowLayout.swift 3 | // SCSectionBackground 4 | // 5 | // Created by Catherine Schwartz on 12/02/2016. 6 | // Copyright © 2016 StrawberryCode. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | 11 | class SectionBackgroundFlowLayout: UICollectionViewFlowLayout { 12 | 13 | // MARK: prepareLayout 14 | 15 | override func prepareLayout() { 16 | super.prepareLayout() 17 | 18 | minimumLineSpacing = 8.0 19 | minimumInteritemSpacing = 8.0 20 | sectionInset = UIEdgeInsetsMake(8, 8, 8, 8) 21 | 22 | let width = (UIScreen.mainScreen().bounds.width / 3) - 2 * 8.0 23 | itemSize = CGSizeMake(width, 100) 24 | 25 | registerClass(SCSBCollectionReusableView.self, forDecorationViewOfKind: "sectionBackground") 26 | } 27 | 28 | // MARK: layoutAttributesForElementsInRect 29 | override func layoutAttributesForElementsInRect(rect: CGRect) -> [UICollectionViewLayoutAttributes]? { 30 | let attributes = super.layoutAttributesForElementsInRect(rect) 31 | var allAttributes = [UICollectionViewLayoutAttributes]() 32 | 33 | if let attributes = attributes { 34 | 35 | for attr in attributes { 36 | // Look for the first item in a row 37 | // You can also calculate it by item (remove the second check in the if below and change the tmpWidth and frame origin 38 | if (attr.representedElementCategory == UICollectionElementCategory.Cell && attr.frame.origin.x == self.sectionInset.left) { 39 | 40 | // Create decoration attributes 41 | let decorationAttributes = SCSBCollectionViewLayoutAttributes(forDecorationViewOfKind: "sectionBackground", withIndexPath: attr.indexPath) 42 | // Set the color(s) 43 | if (attr.indexPath.section % 2 == 0) { 44 | decorationAttributes.color = UIColor.greenColor().colorWithAlphaComponent(0.5) 45 | } else { 46 | decorationAttributes.color = UIColor.blueColor().colorWithAlphaComponent(0.5) 47 | } 48 | 49 | // Make the decoration view span the entire row 50 | let tmpWidth = self.collectionView!.contentSize.width 51 | let tmpHeight = self.itemSize.height + self.minimumLineSpacing + self.sectionInset.top / 2 + self.sectionInset.bottom / 2 // or attributes.frame.size.height instead of itemSize.height if dynamic or recalculated 52 | decorationAttributes.frame = CGRectMake(0, attr.frame.origin.y - self.sectionInset.top, tmpWidth, tmpHeight) 53 | 54 | // Set the zIndex to be behind the item 55 | decorationAttributes.zIndex = attr.zIndex - 1 56 | 57 | // Add the attribute to the list 58 | allAttributes.append(decorationAttributes) 59 | } 60 | } 61 | // Combine the items and decorations arrays 62 | allAttributes.appendContentsOf(attributes) 63 | } 64 | 65 | return allAttributes 66 | } 67 | } 68 | 69 | 70 | 71 | class SCSBCollectionViewLayoutAttributes : UICollectionViewLayoutAttributes { 72 | var color: UIColor = UIColor.whiteColor() 73 | 74 | override func copyWithZone(zone: NSZone) -> AnyObject { 75 | let newAttributes: SCSBCollectionViewLayoutAttributes = super.copyWithZone(zone) as! SCSBCollectionViewLayoutAttributes 76 | newAttributes.color = self.color.copyWithZone(zone) as! UIColor 77 | return newAttributes 78 | } 79 | } 80 | 81 | class SCSBCollectionReusableView : UICollectionReusableView { 82 | 83 | override func applyLayoutAttributes(layoutAttributes: UICollectionViewLayoutAttributes) { 84 | super.applyLayoutAttributes(layoutAttributes) 85 | 86 | let scLayoutAttributes = layoutAttributes as! SCSBCollectionViewLayoutAttributes 87 | self.backgroundColor = scLayoutAttributes.color 88 | } 89 | } 90 | -------------------------------------------------------------------------------- /SCSectionBackground/ViewController.swift: -------------------------------------------------------------------------------- 1 | // 2 | // ViewController.swift 3 | // SCSectionBackground 4 | // 5 | // Created by Catherine Schwartz on 12/02/2016. 6 | // Copyright © 2016 StrawberryCode. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | 11 | class ViewController: UIViewController { 12 | 13 | override func viewDidLoad() { 14 | super.viewDidLoad() 15 | // Do any additional setup after loading the view, typically from a nib. 16 | } 17 | 18 | override func didReceiveMemoryWarning() { 19 | super.didReceiveMemoryWarning() 20 | // Dispose of any resources that can be recreated. 21 | } 22 | 23 | 24 | } 25 | 26 | -------------------------------------------------------------------------------- /SCSectionBackgroundTests/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleExecutable 8 | $(EXECUTABLE_NAME) 9 | CFBundleIdentifier 10 | $(PRODUCT_BUNDLE_IDENTIFIER) 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundleName 14 | $(PRODUCT_NAME) 15 | CFBundlePackageType 16 | BNDL 17 | CFBundleShortVersionString 18 | 1.0 19 | CFBundleSignature 20 | ???? 21 | CFBundleVersion 22 | 1 23 | 24 | 25 | -------------------------------------------------------------------------------- /SCSectionBackgroundTests/SCSectionBackgroundTests.swift: -------------------------------------------------------------------------------- 1 | // 2 | // SCSectionBackgroundTests.swift 3 | // SCSectionBackgroundTests 4 | // 5 | // Created by Catherine Schwartz on 12/02/2016. 6 | // Copyright © 2016 StrawberryCode. All rights reserved. 7 | // 8 | 9 | import XCTest 10 | @testable import SCSectionBackground 11 | 12 | class SCSectionBackgroundTests: XCTestCase { 13 | 14 | override func setUp() { 15 | super.setUp() 16 | // Put setup code here. This method is called before the invocation of each test method in the class. 17 | } 18 | 19 | override func tearDown() { 20 | // Put teardown code here. This method is called after the invocation of each test method in the class. 21 | super.tearDown() 22 | } 23 | 24 | func testExample() { 25 | // This is an example of a functional test case. 26 | // Use XCTAssert and related functions to verify your tests produce the correct results. 27 | } 28 | 29 | func testPerformanceExample() { 30 | // This is an example of a performance test case. 31 | self.measureBlock { 32 | // Put the code you want to measure the time of here. 33 | } 34 | } 35 | 36 | } 37 | -------------------------------------------------------------------------------- /SCSectionBackgroundUITests/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleExecutable 8 | $(EXECUTABLE_NAME) 9 | CFBundleIdentifier 10 | $(PRODUCT_BUNDLE_IDENTIFIER) 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundleName 14 | $(PRODUCT_NAME) 15 | CFBundlePackageType 16 | BNDL 17 | CFBundleShortVersionString 18 | 1.0 19 | CFBundleSignature 20 | ???? 21 | CFBundleVersion 22 | 1 23 | 24 | 25 | -------------------------------------------------------------------------------- /SCSectionBackgroundUITests/SCSectionBackgroundUITests.swift: -------------------------------------------------------------------------------- 1 | // 2 | // SCSectionBackgroundUITests.swift 3 | // SCSectionBackgroundUITests 4 | // 5 | // Created by Catherine Schwartz on 12/02/2016. 6 | // Copyright © 2016 StrawberryCode. All rights reserved. 7 | // 8 | 9 | import XCTest 10 | 11 | class SCSectionBackgroundUITests: XCTestCase { 12 | 13 | override func setUp() { 14 | super.setUp() 15 | 16 | // Put setup code here. This method is called before the invocation of each test method in the class. 17 | 18 | // In UI tests it is usually best to stop immediately when a failure occurs. 19 | continueAfterFailure = false 20 | // UI tests must launch the application that they test. Doing this in setup will make sure it happens for each test method. 21 | XCUIApplication().launch() 22 | 23 | // In UI tests it’s important to set the initial state - such as interface orientation - required for your tests before they run. The setUp method is a good place to do this. 24 | } 25 | 26 | override func tearDown() { 27 | // Put teardown code here. This method is called after the invocation of each test method in the class. 28 | super.tearDown() 29 | } 30 | 31 | func testExample() { 32 | // Use recording to get started writing UI tests. 33 | // Use XCTAssert and related functions to verify your tests produce the correct results. 34 | } 35 | 36 | } 37 | --------------------------------------------------------------------------------