├── .gitignore ├── FBLikeLayout Sample.xcodeproj ├── project.pbxproj └── project.xcworkspace │ ├── contents.xcworkspacedata │ └── xcshareddata │ └── FBLikeLayout Sample.xccheckout ├── FBLikeLayout Sample ├── AppDelegate.h ├── AppDelegate.m ├── Base.lproj │ ├── LaunchScreen.xib │ └── Main.storyboard ├── FBLikeLayout │ ├── FBLikeLayout.h │ └── FBLikeLayout.m ├── ImageCollectionViewCell.h ├── ImageCollectionViewCell.m ├── Images.xcassets │ └── AppIcon.appiconset │ │ └── Contents.json ├── Info.plist ├── SampleImages.bundle │ ├── 286812__angry-tiger_p.jpg │ ├── A-tiger-up-close-010.jpg │ ├── Flash207.jpg │ ├── Maltese_Tiger.jpg │ ├── Project_Tiger.jpg │ ├── Siberian_Tiger_by_Malene_Th.jpg │ ├── South-China-Tiger.jpg │ ├── TiGer-tigers-19955050-900-714.jpg │ ├── Tiger-640x433.jpg │ ├── Tiger-Face-770x400.jpg │ ├── Tiger-tigers-32293802-500-627.jpg │ ├── Tiger2.jpg │ ├── arrow-poster.jpg │ ├── flash_by_rattledmachine-d62oesg.jpg │ ├── siberian_tiger_1.jpg │ ├── snow-tiger.jpg │ ├── the-flash-artwork-18.jpg │ ├── theme-tigers.jpg │ ├── tiger_by_gregchapin-d5i53qs.png │ ├── tiger_free.jpg │ └── tumblr_m0sacwHAsz1r9xp88o1_500.jpg ├── ViewController.h ├── ViewController.m └── main.m ├── FBLikeLayout SampleTests ├── FBLikeLayout_SampleTests.m └── Info.plist ├── FBLikeLayout.podspec ├── LICENSE ├── README.md ├── screenshot.png └── screenshot2.png /.gitignore: -------------------------------------------------------------------------------- 1 | # Xcode 2 | # 3 | build/ 4 | *.pbxuser 5 | !default.pbxuser 6 | *.mode1v3 7 | !default.mode1v3 8 | *.mode2v3 9 | !default.mode2v3 10 | *.perspectivev3 11 | !default.perspectivev3 12 | xcuserdata 13 | *.xccheckout 14 | *.moved-aside 15 | DerivedData 16 | *.hmap 17 | *.ipa 18 | *.xcuserstate -------------------------------------------------------------------------------- /FBLikeLayout Sample.xcodeproj/project.pbxproj: -------------------------------------------------------------------------------- 1 | // !$*UTF8*$! 2 | { 3 | archiveVersion = 1; 4 | classes = { 5 | }; 6 | objectVersion = 46; 7 | objects = { 8 | 9 | /* Begin PBXBuildFile section */ 10 | 3CACDA961A6BBB70008794BA /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = 3CACDA951A6BBB70008794BA /* main.m */; }; 11 | 3CACDA991A6BBB70008794BA /* AppDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = 3CACDA981A6BBB70008794BA /* AppDelegate.m */; }; 12 | 3CACDA9C1A6BBB70008794BA /* ViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 3CACDA9B1A6BBB70008794BA /* ViewController.m */; }; 13 | 3CACDA9F1A6BBB70008794BA /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 3CACDA9D1A6BBB70008794BA /* Main.storyboard */; }; 14 | 3CACDAA11A6BBB70008794BA /* Images.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 3CACDAA01A6BBB70008794BA /* Images.xcassets */; }; 15 | 3CACDAA41A6BBB70008794BA /* LaunchScreen.xib in Resources */ = {isa = PBXBuildFile; fileRef = 3CACDAA21A6BBB70008794BA /* LaunchScreen.xib */; }; 16 | 3CACDAB01A6BBB70008794BA /* FBLikeLayout_SampleTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 3CACDAAF1A6BBB70008794BA /* FBLikeLayout_SampleTests.m */; }; 17 | 3CACDABC1A6BBBDC008794BA /* FBLikeLayout.m in Sources */ = {isa = PBXBuildFile; fileRef = 3CACDABB1A6BBBDC008794BA /* FBLikeLayout.m */; }; 18 | 3CACDABE1A6BC495008794BA /* SampleImages.bundle in Resources */ = {isa = PBXBuildFile; fileRef = 3CACDABD1A6BC495008794BA /* SampleImages.bundle */; }; 19 | 3CACDAC11A6BC570008794BA /* ImageCollectionViewCell.m in Sources */ = {isa = PBXBuildFile; fileRef = 3CACDAC01A6BC570008794BA /* ImageCollectionViewCell.m */; }; 20 | /* End PBXBuildFile section */ 21 | 22 | /* Begin PBXContainerItemProxy section */ 23 | 3CACDAAA1A6BBB70008794BA /* PBXContainerItemProxy */ = { 24 | isa = PBXContainerItemProxy; 25 | containerPortal = 3CACDA881A6BBB70008794BA /* Project object */; 26 | proxyType = 1; 27 | remoteGlobalIDString = 3CACDA8F1A6BBB70008794BA; 28 | remoteInfo = "FBLikeLayout Sample"; 29 | }; 30 | /* End PBXContainerItemProxy section */ 31 | 32 | /* Begin PBXFileReference section */ 33 | 3CACDA901A6BBB70008794BA /* FBLikeLayout Sample.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = "FBLikeLayout Sample.app"; sourceTree = BUILT_PRODUCTS_DIR; }; 34 | 3CACDA941A6BBB70008794BA /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 35 | 3CACDA951A6BBB70008794BA /* main.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = main.m; sourceTree = ""; }; 36 | 3CACDA971A6BBB70008794BA /* AppDelegate.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = AppDelegate.h; sourceTree = ""; }; 37 | 3CACDA981A6BBB70008794BA /* AppDelegate.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = AppDelegate.m; sourceTree = ""; }; 38 | 3CACDA9A1A6BBB70008794BA /* ViewController.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = ViewController.h; sourceTree = ""; }; 39 | 3CACDA9B1A6BBB70008794BA /* ViewController.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = ViewController.m; sourceTree = ""; }; 40 | 3CACDA9E1A6BBB70008794BA /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/Main.storyboard; sourceTree = ""; }; 41 | 3CACDAA01A6BBB70008794BA /* Images.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Images.xcassets; sourceTree = ""; }; 42 | 3CACDAA31A6BBB70008794BA /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.xib; name = Base; path = Base.lproj/LaunchScreen.xib; sourceTree = ""; }; 43 | 3CACDAA91A6BBB70008794BA /* FBLikeLayout SampleTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = "FBLikeLayout SampleTests.xctest"; sourceTree = BUILT_PRODUCTS_DIR; }; 44 | 3CACDAAE1A6BBB70008794BA /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 45 | 3CACDAAF1A6BBB70008794BA /* FBLikeLayout_SampleTests.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = FBLikeLayout_SampleTests.m; sourceTree = ""; }; 46 | 3CACDABA1A6BBBDC008794BA /* FBLikeLayout.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = FBLikeLayout.h; sourceTree = ""; }; 47 | 3CACDABB1A6BBBDC008794BA /* FBLikeLayout.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = FBLikeLayout.m; sourceTree = ""; }; 48 | 3CACDABD1A6BC495008794BA /* SampleImages.bundle */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.plug-in"; path = SampleImages.bundle; sourceTree = ""; }; 49 | 3CACDABF1A6BC570008794BA /* ImageCollectionViewCell.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ImageCollectionViewCell.h; sourceTree = ""; }; 50 | 3CACDAC01A6BC570008794BA /* ImageCollectionViewCell.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ImageCollectionViewCell.m; sourceTree = ""; }; 51 | /* End PBXFileReference section */ 52 | 53 | /* Begin PBXFrameworksBuildPhase section */ 54 | 3CACDA8D1A6BBB70008794BA /* Frameworks */ = { 55 | isa = PBXFrameworksBuildPhase; 56 | buildActionMask = 2147483647; 57 | files = ( 58 | ); 59 | runOnlyForDeploymentPostprocessing = 0; 60 | }; 61 | 3CACDAA61A6BBB70008794BA /* Frameworks */ = { 62 | isa = PBXFrameworksBuildPhase; 63 | buildActionMask = 2147483647; 64 | files = ( 65 | ); 66 | runOnlyForDeploymentPostprocessing = 0; 67 | }; 68 | /* End PBXFrameworksBuildPhase section */ 69 | 70 | /* Begin PBXGroup section */ 71 | 3CACDA871A6BBB70008794BA = { 72 | isa = PBXGroup; 73 | children = ( 74 | 3CACDA921A6BBB70008794BA /* FBLikeLayout Sample */, 75 | 3CACDAAC1A6BBB70008794BA /* FBLikeLayout SampleTests */, 76 | 3CACDA911A6BBB70008794BA /* Products */, 77 | ); 78 | sourceTree = ""; 79 | }; 80 | 3CACDA911A6BBB70008794BA /* Products */ = { 81 | isa = PBXGroup; 82 | children = ( 83 | 3CACDA901A6BBB70008794BA /* FBLikeLayout Sample.app */, 84 | 3CACDAA91A6BBB70008794BA /* FBLikeLayout SampleTests.xctest */, 85 | ); 86 | name = Products; 87 | sourceTree = ""; 88 | }; 89 | 3CACDA921A6BBB70008794BA /* FBLikeLayout Sample */ = { 90 | isa = PBXGroup; 91 | children = ( 92 | 3CACDAB91A6BBBA6008794BA /* FBLikeLayout */, 93 | 3CACDA971A6BBB70008794BA /* AppDelegate.h */, 94 | 3CACDA981A6BBB70008794BA /* AppDelegate.m */, 95 | 3CACDA9A1A6BBB70008794BA /* ViewController.h */, 96 | 3CACDA9B1A6BBB70008794BA /* ViewController.m */, 97 | 3CACDABF1A6BC570008794BA /* ImageCollectionViewCell.h */, 98 | 3CACDAC01A6BC570008794BA /* ImageCollectionViewCell.m */, 99 | 3CACDA9D1A6BBB70008794BA /* Main.storyboard */, 100 | 3CACDABD1A6BC495008794BA /* SampleImages.bundle */, 101 | 3CACDAA01A6BBB70008794BA /* Images.xcassets */, 102 | 3CACDAA21A6BBB70008794BA /* LaunchScreen.xib */, 103 | 3CACDA931A6BBB70008794BA /* Supporting Files */, 104 | ); 105 | path = "FBLikeLayout Sample"; 106 | sourceTree = ""; 107 | }; 108 | 3CACDA931A6BBB70008794BA /* Supporting Files */ = { 109 | isa = PBXGroup; 110 | children = ( 111 | 3CACDA941A6BBB70008794BA /* Info.plist */, 112 | 3CACDA951A6BBB70008794BA /* main.m */, 113 | ); 114 | name = "Supporting Files"; 115 | sourceTree = ""; 116 | }; 117 | 3CACDAAC1A6BBB70008794BA /* FBLikeLayout SampleTests */ = { 118 | isa = PBXGroup; 119 | children = ( 120 | 3CACDAAF1A6BBB70008794BA /* FBLikeLayout_SampleTests.m */, 121 | 3CACDAAD1A6BBB70008794BA /* Supporting Files */, 122 | ); 123 | path = "FBLikeLayout SampleTests"; 124 | sourceTree = ""; 125 | }; 126 | 3CACDAAD1A6BBB70008794BA /* Supporting Files */ = { 127 | isa = PBXGroup; 128 | children = ( 129 | 3CACDAAE1A6BBB70008794BA /* Info.plist */, 130 | ); 131 | name = "Supporting Files"; 132 | sourceTree = ""; 133 | }; 134 | 3CACDAB91A6BBBA6008794BA /* FBLikeLayout */ = { 135 | isa = PBXGroup; 136 | children = ( 137 | 3CACDABA1A6BBBDC008794BA /* FBLikeLayout.h */, 138 | 3CACDABB1A6BBBDC008794BA /* FBLikeLayout.m */, 139 | ); 140 | path = FBLikeLayout; 141 | sourceTree = ""; 142 | }; 143 | /* End PBXGroup section */ 144 | 145 | /* Begin PBXNativeTarget section */ 146 | 3CACDA8F1A6BBB70008794BA /* FBLikeLayout Sample */ = { 147 | isa = PBXNativeTarget; 148 | buildConfigurationList = 3CACDAB31A6BBB70008794BA /* Build configuration list for PBXNativeTarget "FBLikeLayout Sample" */; 149 | buildPhases = ( 150 | 3CACDA8C1A6BBB70008794BA /* Sources */, 151 | 3CACDA8D1A6BBB70008794BA /* Frameworks */, 152 | 3CACDA8E1A6BBB70008794BA /* Resources */, 153 | ); 154 | buildRules = ( 155 | ); 156 | dependencies = ( 157 | ); 158 | name = "FBLikeLayout Sample"; 159 | productName = "FBLikeLayout Sample"; 160 | productReference = 3CACDA901A6BBB70008794BA /* FBLikeLayout Sample.app */; 161 | productType = "com.apple.product-type.application"; 162 | }; 163 | 3CACDAA81A6BBB70008794BA /* FBLikeLayout SampleTests */ = { 164 | isa = PBXNativeTarget; 165 | buildConfigurationList = 3CACDAB61A6BBB70008794BA /* Build configuration list for PBXNativeTarget "FBLikeLayout SampleTests" */; 166 | buildPhases = ( 167 | 3CACDAA51A6BBB70008794BA /* Sources */, 168 | 3CACDAA61A6BBB70008794BA /* Frameworks */, 169 | 3CACDAA71A6BBB70008794BA /* Resources */, 170 | ); 171 | buildRules = ( 172 | ); 173 | dependencies = ( 174 | 3CACDAAB1A6BBB70008794BA /* PBXTargetDependency */, 175 | ); 176 | name = "FBLikeLayout SampleTests"; 177 | productName = "FBLikeLayout SampleTests"; 178 | productReference = 3CACDAA91A6BBB70008794BA /* FBLikeLayout SampleTests.xctest */; 179 | productType = "com.apple.product-type.bundle.unit-test"; 180 | }; 181 | /* End PBXNativeTarget section */ 182 | 183 | /* Begin PBXProject section */ 184 | 3CACDA881A6BBB70008794BA /* Project object */ = { 185 | isa = PBXProject; 186 | attributes = { 187 | LastUpgradeCheck = 0610; 188 | ORGANIZATIONNAME = "La Nuova Era"; 189 | TargetAttributes = { 190 | 3CACDA8F1A6BBB70008794BA = { 191 | CreatedOnToolsVersion = 6.1.1; 192 | }; 193 | 3CACDAA81A6BBB70008794BA = { 194 | CreatedOnToolsVersion = 6.1.1; 195 | TestTargetID = 3CACDA8F1A6BBB70008794BA; 196 | }; 197 | }; 198 | }; 199 | buildConfigurationList = 3CACDA8B1A6BBB70008794BA /* Build configuration list for PBXProject "FBLikeLayout Sample" */; 200 | compatibilityVersion = "Xcode 3.2"; 201 | developmentRegion = English; 202 | hasScannedForEncodings = 0; 203 | knownRegions = ( 204 | en, 205 | Base, 206 | ); 207 | mainGroup = 3CACDA871A6BBB70008794BA; 208 | productRefGroup = 3CACDA911A6BBB70008794BA /* Products */; 209 | projectDirPath = ""; 210 | projectRoot = ""; 211 | targets = ( 212 | 3CACDA8F1A6BBB70008794BA /* FBLikeLayout Sample */, 213 | 3CACDAA81A6BBB70008794BA /* FBLikeLayout SampleTests */, 214 | ); 215 | }; 216 | /* End PBXProject section */ 217 | 218 | /* Begin PBXResourcesBuildPhase section */ 219 | 3CACDA8E1A6BBB70008794BA /* Resources */ = { 220 | isa = PBXResourcesBuildPhase; 221 | buildActionMask = 2147483647; 222 | files = ( 223 | 3CACDA9F1A6BBB70008794BA /* Main.storyboard in Resources */, 224 | 3CACDAA41A6BBB70008794BA /* LaunchScreen.xib in Resources */, 225 | 3CACDAA11A6BBB70008794BA /* Images.xcassets in Resources */, 226 | 3CACDABE1A6BC495008794BA /* SampleImages.bundle in Resources */, 227 | ); 228 | runOnlyForDeploymentPostprocessing = 0; 229 | }; 230 | 3CACDAA71A6BBB70008794BA /* Resources */ = { 231 | isa = PBXResourcesBuildPhase; 232 | buildActionMask = 2147483647; 233 | files = ( 234 | ); 235 | runOnlyForDeploymentPostprocessing = 0; 236 | }; 237 | /* End PBXResourcesBuildPhase section */ 238 | 239 | /* Begin PBXSourcesBuildPhase section */ 240 | 3CACDA8C1A6BBB70008794BA /* Sources */ = { 241 | isa = PBXSourcesBuildPhase; 242 | buildActionMask = 2147483647; 243 | files = ( 244 | 3CACDABC1A6BBBDC008794BA /* FBLikeLayout.m in Sources */, 245 | 3CACDA9C1A6BBB70008794BA /* ViewController.m in Sources */, 246 | 3CACDAC11A6BC570008794BA /* ImageCollectionViewCell.m in Sources */, 247 | 3CACDA991A6BBB70008794BA /* AppDelegate.m in Sources */, 248 | 3CACDA961A6BBB70008794BA /* main.m in Sources */, 249 | ); 250 | runOnlyForDeploymentPostprocessing = 0; 251 | }; 252 | 3CACDAA51A6BBB70008794BA /* Sources */ = { 253 | isa = PBXSourcesBuildPhase; 254 | buildActionMask = 2147483647; 255 | files = ( 256 | 3CACDAB01A6BBB70008794BA /* FBLikeLayout_SampleTests.m in Sources */, 257 | ); 258 | runOnlyForDeploymentPostprocessing = 0; 259 | }; 260 | /* End PBXSourcesBuildPhase section */ 261 | 262 | /* Begin PBXTargetDependency section */ 263 | 3CACDAAB1A6BBB70008794BA /* PBXTargetDependency */ = { 264 | isa = PBXTargetDependency; 265 | target = 3CACDA8F1A6BBB70008794BA /* FBLikeLayout Sample */; 266 | targetProxy = 3CACDAAA1A6BBB70008794BA /* PBXContainerItemProxy */; 267 | }; 268 | /* End PBXTargetDependency section */ 269 | 270 | /* Begin PBXVariantGroup section */ 271 | 3CACDA9D1A6BBB70008794BA /* Main.storyboard */ = { 272 | isa = PBXVariantGroup; 273 | children = ( 274 | 3CACDA9E1A6BBB70008794BA /* Base */, 275 | ); 276 | name = Main.storyboard; 277 | sourceTree = ""; 278 | }; 279 | 3CACDAA21A6BBB70008794BA /* LaunchScreen.xib */ = { 280 | isa = PBXVariantGroup; 281 | children = ( 282 | 3CACDAA31A6BBB70008794BA /* Base */, 283 | ); 284 | name = LaunchScreen.xib; 285 | sourceTree = ""; 286 | }; 287 | /* End PBXVariantGroup section */ 288 | 289 | /* Begin XCBuildConfiguration section */ 290 | 3CACDAB11A6BBB70008794BA /* Debug */ = { 291 | isa = XCBuildConfiguration; 292 | buildSettings = { 293 | ALWAYS_SEARCH_USER_PATHS = NO; 294 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; 295 | CLANG_CXX_LIBRARY = "libc++"; 296 | CLANG_ENABLE_MODULES = YES; 297 | CLANG_ENABLE_OBJC_ARC = YES; 298 | CLANG_WARN_BOOL_CONVERSION = YES; 299 | CLANG_WARN_CONSTANT_CONVERSION = YES; 300 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 301 | CLANG_WARN_EMPTY_BODY = YES; 302 | CLANG_WARN_ENUM_CONVERSION = YES; 303 | CLANG_WARN_INT_CONVERSION = YES; 304 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 305 | CLANG_WARN_UNREACHABLE_CODE = YES; 306 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 307 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; 308 | COPY_PHASE_STRIP = NO; 309 | ENABLE_STRICT_OBJC_MSGSEND = YES; 310 | GCC_C_LANGUAGE_STANDARD = gnu99; 311 | GCC_DYNAMIC_NO_PIC = NO; 312 | GCC_OPTIMIZATION_LEVEL = 0; 313 | GCC_PREPROCESSOR_DEFINITIONS = ( 314 | "DEBUG=1", 315 | "$(inherited)", 316 | ); 317 | GCC_SYMBOLS_PRIVATE_EXTERN = NO; 318 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 319 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 320 | GCC_WARN_UNDECLARED_SELECTOR = YES; 321 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 322 | GCC_WARN_UNUSED_FUNCTION = YES; 323 | GCC_WARN_UNUSED_VARIABLE = YES; 324 | IPHONEOS_DEPLOYMENT_TARGET = 8.1; 325 | MTL_ENABLE_DEBUG_INFO = YES; 326 | ONLY_ACTIVE_ARCH = YES; 327 | SDKROOT = iphoneos; 328 | TARGETED_DEVICE_FAMILY = "1,2"; 329 | }; 330 | name = Debug; 331 | }; 332 | 3CACDAB21A6BBB70008794BA /* Release */ = { 333 | isa = XCBuildConfiguration; 334 | buildSettings = { 335 | ALWAYS_SEARCH_USER_PATHS = NO; 336 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; 337 | CLANG_CXX_LIBRARY = "libc++"; 338 | CLANG_ENABLE_MODULES = YES; 339 | CLANG_ENABLE_OBJC_ARC = YES; 340 | CLANG_WARN_BOOL_CONVERSION = YES; 341 | CLANG_WARN_CONSTANT_CONVERSION = YES; 342 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 343 | CLANG_WARN_EMPTY_BODY = YES; 344 | CLANG_WARN_ENUM_CONVERSION = YES; 345 | CLANG_WARN_INT_CONVERSION = YES; 346 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 347 | CLANG_WARN_UNREACHABLE_CODE = YES; 348 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 349 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; 350 | COPY_PHASE_STRIP = YES; 351 | ENABLE_NS_ASSERTIONS = NO; 352 | ENABLE_STRICT_OBJC_MSGSEND = YES; 353 | GCC_C_LANGUAGE_STANDARD = gnu99; 354 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 355 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 356 | GCC_WARN_UNDECLARED_SELECTOR = YES; 357 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 358 | GCC_WARN_UNUSED_FUNCTION = YES; 359 | GCC_WARN_UNUSED_VARIABLE = YES; 360 | IPHONEOS_DEPLOYMENT_TARGET = 8.1; 361 | MTL_ENABLE_DEBUG_INFO = NO; 362 | SDKROOT = iphoneos; 363 | TARGETED_DEVICE_FAMILY = "1,2"; 364 | VALIDATE_PRODUCT = YES; 365 | }; 366 | name = Release; 367 | }; 368 | 3CACDAB41A6BBB70008794BA /* Debug */ = { 369 | isa = XCBuildConfiguration; 370 | buildSettings = { 371 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 372 | INFOPLIST_FILE = "FBLikeLayout Sample/Info.plist"; 373 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; 374 | PRODUCT_NAME = "$(TARGET_NAME)"; 375 | }; 376 | name = Debug; 377 | }; 378 | 3CACDAB51A6BBB70008794BA /* Release */ = { 379 | isa = XCBuildConfiguration; 380 | buildSettings = { 381 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 382 | INFOPLIST_FILE = "FBLikeLayout Sample/Info.plist"; 383 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; 384 | PRODUCT_NAME = "$(TARGET_NAME)"; 385 | }; 386 | name = Release; 387 | }; 388 | 3CACDAB71A6BBB70008794BA /* Debug */ = { 389 | isa = XCBuildConfiguration; 390 | buildSettings = { 391 | BUNDLE_LOADER = "$(TEST_HOST)"; 392 | FRAMEWORK_SEARCH_PATHS = ( 393 | "$(SDKROOT)/Developer/Library/Frameworks", 394 | "$(inherited)", 395 | ); 396 | GCC_PREPROCESSOR_DEFINITIONS = ( 397 | "DEBUG=1", 398 | "$(inherited)", 399 | ); 400 | INFOPLIST_FILE = "FBLikeLayout SampleTests/Info.plist"; 401 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; 402 | PRODUCT_NAME = "$(TARGET_NAME)"; 403 | TEST_HOST = "$(BUILT_PRODUCTS_DIR)/FBLikeLayout Sample.app/FBLikeLayout Sample"; 404 | }; 405 | name = Debug; 406 | }; 407 | 3CACDAB81A6BBB70008794BA /* Release */ = { 408 | isa = XCBuildConfiguration; 409 | buildSettings = { 410 | BUNDLE_LOADER = "$(TEST_HOST)"; 411 | FRAMEWORK_SEARCH_PATHS = ( 412 | "$(SDKROOT)/Developer/Library/Frameworks", 413 | "$(inherited)", 414 | ); 415 | INFOPLIST_FILE = "FBLikeLayout SampleTests/Info.plist"; 416 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; 417 | PRODUCT_NAME = "$(TARGET_NAME)"; 418 | TEST_HOST = "$(BUILT_PRODUCTS_DIR)/FBLikeLayout Sample.app/FBLikeLayout Sample"; 419 | }; 420 | name = Release; 421 | }; 422 | /* End XCBuildConfiguration section */ 423 | 424 | /* Begin XCConfigurationList section */ 425 | 3CACDA8B1A6BBB70008794BA /* Build configuration list for PBXProject "FBLikeLayout Sample" */ = { 426 | isa = XCConfigurationList; 427 | buildConfigurations = ( 428 | 3CACDAB11A6BBB70008794BA /* Debug */, 429 | 3CACDAB21A6BBB70008794BA /* Release */, 430 | ); 431 | defaultConfigurationIsVisible = 0; 432 | defaultConfigurationName = Release; 433 | }; 434 | 3CACDAB31A6BBB70008794BA /* Build configuration list for PBXNativeTarget "FBLikeLayout Sample" */ = { 435 | isa = XCConfigurationList; 436 | buildConfigurations = ( 437 | 3CACDAB41A6BBB70008794BA /* Debug */, 438 | 3CACDAB51A6BBB70008794BA /* Release */, 439 | ); 440 | defaultConfigurationIsVisible = 0; 441 | }; 442 | 3CACDAB61A6BBB70008794BA /* Build configuration list for PBXNativeTarget "FBLikeLayout SampleTests" */ = { 443 | isa = XCConfigurationList; 444 | buildConfigurations = ( 445 | 3CACDAB71A6BBB70008794BA /* Debug */, 446 | 3CACDAB81A6BBB70008794BA /* Release */, 447 | ); 448 | defaultConfigurationIsVisible = 0; 449 | }; 450 | /* End XCConfigurationList section */ 451 | }; 452 | rootObject = 3CACDA881A6BBB70008794BA /* Project object */; 453 | } 454 | -------------------------------------------------------------------------------- /FBLikeLayout Sample.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /FBLikeLayout Sample.xcodeproj/project.xcworkspace/xcshareddata/FBLikeLayout Sample.xccheckout: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | IDESourceControlProjectFavoriteDictionaryKey 6 | 7 | IDESourceControlProjectIdentifier 8 | A64DE99A-6976-4CF7-8C9C-59A7BE2BEDC3 9 | IDESourceControlProjectName 10 | FBLikeLayout Sample 11 | IDESourceControlProjectOriginsDictionary 12 | 13 | E56A4AD3F137493D542219BD13FA3212EDD1296E 14 | https://github.com/gringoireDM/FBLikeLayout.git 15 | 16 | IDESourceControlProjectPath 17 | FBLikeLayout Sample.xcodeproj 18 | IDESourceControlProjectRelativeInstallPathDictionary 19 | 20 | E56A4AD3F137493D542219BD13FA3212EDD1296E 21 | ../.. 22 | 23 | IDESourceControlProjectURL 24 | https://github.com/gringoireDM/FBLikeLayout.git 25 | IDESourceControlProjectVersion 26 | 111 27 | IDESourceControlProjectWCCIdentifier 28 | E56A4AD3F137493D542219BD13FA3212EDD1296E 29 | IDESourceControlProjectWCConfigurations 30 | 31 | 32 | IDESourceControlRepositoryExtensionIdentifierKey 33 | public.vcs.git 34 | IDESourceControlWCCIdentifierKey 35 | E56A4AD3F137493D542219BD13FA3212EDD1296E 36 | IDESourceControlWCCName 37 | FBLikeLayout%20Sample 38 | 39 | 40 | 41 | 42 | -------------------------------------------------------------------------------- /FBLikeLayout Sample/AppDelegate.h: -------------------------------------------------------------------------------- 1 | // 2 | // AppDelegate.h 3 | // FBLikeLayout Sample 4 | // 5 | // Created by Giuseppe Lanza on 18/01/15. 6 | // Copyright (c) 2015 La Nuova Era. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface AppDelegate : UIResponder 12 | 13 | @property (strong, nonatomic) UIWindow *window; 14 | 15 | 16 | @end 17 | 18 | -------------------------------------------------------------------------------- /FBLikeLayout Sample/AppDelegate.m: -------------------------------------------------------------------------------- 1 | // 2 | // AppDelegate.m 3 | // FBLikeLayout Sample 4 | // 5 | // Created by Giuseppe Lanza on 18/01/15. 6 | // Copyright (c) 2015 La Nuova Era. All rights reserved. 7 | // 8 | 9 | #import "AppDelegate.h" 10 | 11 | @interface AppDelegate () 12 | 13 | @end 14 | 15 | @implementation AppDelegate 16 | 17 | 18 | - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { 19 | // Override point for customization after application launch. 20 | return YES; 21 | } 22 | 23 | - (void)applicationWillResignActive:(UIApplication *)application { 24 | // 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. 25 | // 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. 26 | } 27 | 28 | - (void)applicationDidEnterBackground:(UIApplication *)application { 29 | // 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. 30 | // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits. 31 | } 32 | 33 | - (void)applicationWillEnterForeground:(UIApplication *)application { 34 | // 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. 35 | } 36 | 37 | - (void)applicationDidBecomeActive:(UIApplication *)application { 38 | // 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. 39 | } 40 | 41 | - (void)applicationWillTerminate:(UIApplication *)application { 42 | // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:. 43 | } 44 | 45 | @end 46 | -------------------------------------------------------------------------------- /FBLikeLayout Sample/Base.lproj/LaunchScreen.xib: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 20 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | -------------------------------------------------------------------------------- /FBLikeLayout Sample/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 | -------------------------------------------------------------------------------- /FBLikeLayout Sample/FBLikeLayout/FBLikeLayout.h: -------------------------------------------------------------------------------- 1 | // 2 | // FBLikeLayout.h 3 | // FPhoto Manager 4 | // 5 | // Created by Giuseppe Lanza on 27/12/14. 6 | // Copyright (c) 2014 lanuovaera. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | 12 | //WARNING: in order to get this layout working you MUST implement the collectionView:layout:sizeForItemAtIndexPath: delegate method, or you will have only squared cells. 13 | 14 | @interface FBLikeLayout : UICollectionViewFlowLayout 15 | 16 | //The minimum width for a single cell This is intended as the width when the cell is a square. 17 | @property (nonatomic, assign) CGFloat singleCellWidth; 18 | 19 | //The max number of cells space that a single cell can have horizontally. Defaults to 3. A single cell space is intended to be the single square place. 20 | @property (nonatomic, assign) NSInteger maxCellSpace; 21 | 22 | //set to YES if you want the minimumInteritemSpace to be respected ALWAYS. The singleCellWidth Will be at this point the MINIMUM cell width, and will be resized in order to fit the criteria. 23 | @property (nonatomic, assign) BOOL forceCellWidthForMinimumInteritemSpacing; 24 | 25 | //The probability that the cell will be a full image cell expressed in percentage (1 to 100). Defaults to 30. set to -1 if you only need squared cells. No full images would be displayed in this case. 26 | @property (nonatomic, assign) NSInteger fullImagePercentageOfOccurrency; 27 | 28 | @end 29 | -------------------------------------------------------------------------------- /FBLikeLayout Sample/FBLikeLayout/FBLikeLayout.m: -------------------------------------------------------------------------------- 1 | // 2 | // FBLikeLayout.m 3 | // FPhoto Manager 4 | // 5 | // Created by Giuseppe Lanza on 27/12/14. 6 | // Copyright (c) 2014 lanuovaera. All rights reserved. 7 | // 8 | 9 | #import "FBLikeLayout.h" 10 | 11 | @interface MatrixElement : NSObject 12 | 13 | @property (nonatomic, assign) CGRect frame; 14 | @property (nonatomic, assign) NSInteger columns; 15 | @property (nonatomic, assign) NSInteger rows; 16 | @property (nonatomic, copy) NSIndexPath *indexPath; 17 | @property (nonatomic, strong) UICollectionViewLayoutAttributes *attributes; 18 | 19 | @end 20 | 21 | @implementation MatrixElement 22 | 23 | -(instancetype)init{ 24 | self = [super init]; 25 | 26 | if(self){ 27 | self.frame = CGRectZero; 28 | self.columns = 0; 29 | self.rows = 0; 30 | self.indexPath = nil; 31 | } 32 | 33 | return self; 34 | } 35 | 36 | -(NSString *)description{ 37 | return [NSString stringWithFormat:@"MatrixElemnt %lix%li for indexPath: %li - %li, frame: %@", self.columns, self.rows, self.indexPath.item, self.indexPath.section, NSStringFromCGRect(self.frame)]; 38 | } 39 | 40 | @end 41 | 42 | @interface FBLikeLayout() 43 | 44 | @property (nonatomic, strong) NSMutableDictionary *attributesForIndexPath; 45 | @property (nonatomic, strong) NSMutableDictionary *framesForHeaderSection; 46 | @property (nonatomic, strong) NSMutableDictionary *framesForFooterSection; 47 | @property (nonatomic, strong) NSMutableArray *sectionMatrices; 48 | 49 | @property (nonatomic, assign) CGSize contentSize; 50 | 51 | @end 52 | 53 | #ifndef DLog 54 | #if DEBUG 55 | #define DLog(fmt, ...) NSLog((@"%s [Line %d] " fmt), __PRETTY_FUNCTION__, __LINE__, ##__VA_ARGS__); 56 | #else 57 | #define DLog(...) 58 | #endif 59 | #endif 60 | 61 | @implementation FBLikeLayout 62 | 63 | #if DEBUG 64 | 65 | -(void)dealloc{ 66 | //DLog(@"Dealloc called"); 67 | } 68 | 69 | #endif 70 | 71 | -(NSMutableDictionary *)attributesForIndexPath{ 72 | if(!_attributesForIndexPath){ 73 | _attributesForIndexPath = [NSMutableDictionary new]; 74 | } 75 | 76 | return _attributesForIndexPath; 77 | } 78 | 79 | -(NSMutableDictionary *)framesForHeaderSection{ 80 | if(!_framesForHeaderSection) _framesForHeaderSection = [NSMutableDictionary new]; 81 | 82 | return _framesForHeaderSection; 83 | } 84 | 85 | -(NSMutableDictionary *)framesForFooterSection{ 86 | if(!_framesForFooterSection) _framesForFooterSection = [NSMutableDictionary new]; 87 | 88 | return _framesForFooterSection; 89 | } 90 | 91 | -(NSMutableArray *)sectionMatrices{ 92 | if(!_sectionMatrices) 93 | _sectionMatrices = [NSMutableArray new]; 94 | 95 | return _sectionMatrices; 96 | } 97 | 98 | -(NSInteger) voidElementsInRow:(NSArray *) row fromColumn:(NSInteger)column{ 99 | NSInteger count = 0; 100 | 101 | for(NSInteger i = column; i < row.count; i++){ 102 | if(CGRectIsEmpty([(MatrixElement *)row[i] frame])){ 103 | count++; 104 | } else { 105 | break; 106 | } 107 | } 108 | 109 | return count; 110 | } 111 | 112 | -(void)prepareLayout{ 113 | if(self.singleCellWidth == 0){ 114 | self.singleCellWidth = (MIN(self.collectionView.bounds.size.width, self.collectionView.bounds.size.height)-self.collectionView.contentInset.left-self.collectionView.contentInset.right-2*self.minimumInteritemSpacing)/3.0; 115 | } 116 | 117 | if(self.fullImagePercentageOfOccurrency == 0) 118 | self.fullImagePercentageOfOccurrency = 70; 119 | 120 | CGFloat cellWidthToUse = self.singleCellWidth; 121 | 122 | if(self.maxCellSpace == 0) 123 | self.maxCellSpace = 3; 124 | 125 | int columns = floorf((self.collectionView.bounds.size.width-self.collectionView.contentInset.left-self.collectionView.contentInset.right)/cellWidthToUse); 126 | 127 | CGFloat realInteritemSpacing = MAX(self.minimumInteritemSpacing, (self.collectionView.bounds.size.width-self.collectionView.contentInset.left-self.collectionView.contentInset.right-(float)columns*cellWidthToUse)/(columns-1)); 128 | 129 | if(self.forceCellWidthForMinimumInteritemSpacing && realInteritemSpacing != self.minimumInteritemSpacing){ 130 | cellWidthToUse = (self.collectionView.bounds.size.width-self.collectionView.contentInset.left-self.collectionView.contentInset.right-self.minimumInteritemSpacing*(columns-1))/columns; 131 | 132 | realInteritemSpacing = self.minimumInteritemSpacing; 133 | } 134 | 135 | NSInteger sections = [self.collectionView numberOfSections]; 136 | 137 | CGFloat maxH = 0; 138 | 139 | __block CGPoint offset = CGPointZero; 140 | 141 | for(NSInteger section = 0; section < sections; section++){ 142 | NSInteger items = [self.collectionView numberOfItemsInSection:section]; 143 | 144 | //Section Header 145 | if([self.collectionView.delegate conformsToProtocol:@protocol(UICollectionViewDelegateFlowLayout)] && [(id)self.collectionView.delegate respondsToSelector:@selector(collectionView:layout:referenceSizeForHeaderInSection:)]){ 146 | CGSize headerSize = [(id)self.collectionView.delegate collectionView:self.collectionView layout:self referenceSizeForHeaderInSection:section]; 147 | 148 | CGRect headerFrame = CGRectMake(-self.collectionView.contentInset.left, (section == 0? 0: 2*realInteritemSpacing)+maxH, self.collectionView.bounds.size.width, headerSize.height); 149 | self.framesForHeaderSection[@(section)] = [NSValue valueWithCGRect:headerFrame]; 150 | 151 | maxH += headerFrame.size.height+realInteritemSpacing+(section == 0? 0: 2*realInteritemSpacing); 152 | offset.x = 0; 153 | offset.y = maxH; 154 | } 155 | 156 | NSInteger currentRow = 0; 157 | NSInteger currentColumn = 0; 158 | 159 | NSMutableArray *reticleMatrix = nil; 160 | NSMutableDictionary *boundedMatrices = nil; 161 | 162 | if(section < self.sectionMatrices.count){ 163 | boundedMatrices = self.sectionMatrices[section]; 164 | 165 | } else { 166 | boundedMatrices = [NSMutableDictionary new]; 167 | [self.sectionMatrices addObject:boundedMatrices]; 168 | } 169 | 170 | 171 | if(boundedMatrices[NSStringFromCGSize(self.collectionView.bounds.size)]){ 172 | reticleMatrix = boundedMatrices[NSStringFromCGSize(self.collectionView.bounds.size)]; 173 | } else{ 174 | reticleMatrix = [NSMutableArray new]; 175 | boundedMatrices[NSStringFromCGSize(self.collectionView.bounds.size)] = reticleMatrix; 176 | } 177 | CGFloat oldOffset = [boundedMatrices[@"sectionOffset"] floatValue]; 178 | boundedMatrices[@"sectionOffset"] = @(maxH); 179 | BOOL lastCached = NO; 180 | 181 | for(NSInteger item = 0; item < items; item++){ 182 | NSIndexPath *indexPath = [NSIndexPath indexPathForItem:item inSection:section]; 183 | NSPredicate *predicate = [NSPredicate predicateWithFormat:@"SUBQUERY(SELF.indexPath, $a, $a == %@).@count != 0", indexPath]; 184 | 185 | NSArray *row = [[reticleMatrix filteredArrayUsingPredicate:predicate] firstObject]; 186 | 187 | MatrixElement *thisElement = nil; 188 | if(row){ 189 | for(MatrixElement *element in row){ 190 | if([element.indexPath isEqual:indexPath]) 191 | thisElement = element; 192 | } 193 | 194 | currentRow = [reticleMatrix indexOfObject:row]; 195 | currentColumn = [row indexOfObject:thisElement]; 196 | //DLog(@"Restoring item %li, %li", currentRow, currentColumn); 197 | 198 | CGRect frame = thisElement.frame; 199 | frame.origin.y -= oldOffset; 200 | frame.origin.y += [boundedMatrices[@"sectionOffset"] floatValue]; 201 | 202 | offset.x = frame.origin.x; 203 | offset.y = frame.origin.y; 204 | 205 | thisElement.frame = frame; 206 | thisElement.attributes.frame = frame; 207 | 208 | if(maxH < CGRectGetMaxY(frame)){ 209 | maxH = CGRectGetMaxY(frame); 210 | } 211 | 212 | self.attributesForIndexPath[indexPath] = thisElement.attributes; 213 | 214 | //update the current row and column and offsets 215 | lastCached = YES; 216 | } else { 217 | if(lastCached){ 218 | [self findNextFreeCell:¤tRow currentColumn:¤tColumn reticleMatrix:reticleMatrix withdidAddRowBlock:^{ 219 | offset.y += cellWidthToUse+realInteritemSpacing; 220 | }]; 221 | } 222 | 223 | lastCached = NO; 224 | 225 | CGSize thisCellSize = CGSizeMake(cellWidthToUse, cellWidthToUse); 226 | 227 | NSMutableArray *currentRowArray = nil; 228 | if (currentColumn == 0 && reticleMatrix.count <= currentRow){ 229 | currentRowArray = [self addRowOfItems:columns]; 230 | [reticleMatrix addObject:currentRowArray]; 231 | } else { 232 | currentRowArray = [reticleMatrix objectAtIndex:currentRow]; 233 | } 234 | 235 | offset.x = currentColumn*(cellWidthToUse+realInteritemSpacing); 236 | 237 | MatrixElement *thisCellElement = currentRowArray[currentColumn]; 238 | thisCellElement.indexPath = indexPath; 239 | thisCellElement.columns = 1; 240 | thisCellElement.rows = 1; 241 | 242 | if([self.collectionView.delegate conformsToProtocol:@protocol(UICollectionViewDelegateFlowLayout)] && [(id)self.collectionView.delegate respondsToSelector:@selector(collectionView:layout:sizeForItemAtIndexPath:)]){ 243 | CGSize preferredItemSize = [(id)self.collectionView.delegate collectionView:self.collectionView layout:self sizeForItemAtIndexPath:indexPath]; 244 | 245 | //if it is > 1 then the photo is in landscape else it is in portrait or it is squared 246 | CGFloat cellRatio = preferredItemSize.width/preferredItemSize.height; 247 | 248 | NSInteger leftColumns = [self voidElementsInRow:currentRowArray fromColumn:currentColumn]; 249 | //DLog(@"current column %li leftColumns %li", (long)currentColumn, (long)leftColumns); 250 | 251 | if(self.fullImagePercentageOfOccurrency != -1 && currentColumn < columns && leftColumns >= self.maxCellSpace-1){ 252 | int roll = 1+arc4random()%100; 253 | 254 | if(roll >= 100-self.fullImagePercentageOfOccurrency){ 255 | NSInteger numberOfWColumns = MIN((cellRatio <= 1 ? self.maxCellSpace-1: self.maxCellSpace), leftColumns); 256 | NSInteger numberOfYColumns = MAX(1, roundf(numberOfWColumns/cellRatio)); 257 | 258 | if(fabs(numberOfYColumns-numberOfWColumns) >= 1){ 259 | 260 | //DLog(@"nonSquaredCell: %li x %li", (long)numberOfWColumns, (long)numberOfYColumns); 261 | 262 | CGFloat width = cellWidthToUse*numberOfWColumns + (numberOfWColumns-1)*realInteritemSpacing; 263 | CGFloat height = cellWidthToUse*numberOfYColumns + (numberOfYColumns-1)*realInteritemSpacing; 264 | 265 | thisCellSize = CGSizeMake(width, height); 266 | 267 | thisCellElement.columns = numberOfWColumns; 268 | thisCellElement.rows = numberOfYColumns; 269 | 270 | for(NSInteger j = currentRow; j < currentRow+numberOfYColumns; j++){ 271 | NSMutableArray *processingRow = nil; 272 | if(reticleMatrix.count <= j){ 273 | processingRow = [self addRowOfItems:columns]; 274 | [reticleMatrix addObject:processingRow]; 275 | } else { 276 | processingRow = reticleMatrix[j]; 277 | } 278 | 279 | for(NSInteger i = currentColumn; i < currentColumn+numberOfWColumns; i++){ 280 | [processingRow replaceObjectAtIndex:i withObject:thisCellElement]; 281 | } 282 | } 283 | } 284 | } 285 | } 286 | 287 | CGRect thisCellRect = CGRectMake(offset.x, offset.y, thisCellSize.width, thisCellSize.height); 288 | thisCellElement.frame = thisCellRect; 289 | 290 | if(maxH < CGRectGetMaxY(thisCellRect)){ 291 | maxH = CGRectGetMaxY(thisCellRect); 292 | } 293 | 294 | UICollectionViewLayoutAttributes *attributes = [UICollectionViewLayoutAttributes layoutAttributesForCellWithIndexPath:indexPath]; 295 | attributes.frame = thisCellRect; 296 | 297 | thisCellElement.attributes = attributes; 298 | self.attributesForIndexPath[indexPath] = thisCellElement.attributes; 299 | 300 | //next free cell 301 | [self findNextFreeCell:¤tRow currentColumn:¤tColumn reticleMatrix:reticleMatrix withdidAddRowBlock:^{ 302 | offset.y += cellWidthToUse+realInteritemSpacing; 303 | }]; 304 | } 305 | 306 | } 307 | 308 | } 309 | 310 | 311 | //[self printMatrix:reticleMatrix]; 312 | //section footer 313 | 314 | if([self.collectionView.delegate conformsToProtocol:@protocol(UICollectionViewDelegateFlowLayout)] && [(id)self.collectionView.delegate respondsToSelector:@selector(collectionView:layout:referenceSizeForFooterInSection:)]){ 315 | CGSize footerSize = [(id)self.collectionView.delegate collectionView:self.collectionView layout:self referenceSizeForFooterInSection:section]; 316 | 317 | CGRect footerFrame = CGRectMake(-self.collectionView.contentInset.left, maxH+realInteritemSpacing, self.collectionView.bounds.size.width, footerSize.height); 318 | self.framesForFooterSection[@(section)] = [NSValue valueWithCGRect:footerFrame]; 319 | 320 | maxH += footerFrame.size.height; 321 | offset.x = 0; 322 | offset.y = maxH; 323 | } 324 | } 325 | 326 | self.contentSize = CGSizeMake(self.collectionView.bounds.size.width-self.collectionView.contentInset.left-self.collectionView.contentInset.right, maxH); 327 | } 328 | 329 | -(void) findNextFreeCell:(NSInteger *) currentRow currentColumn:(NSInteger *)currentColumn reticleMatrix:(NSMutableArray *) reticleMatrix withdidAddRowBlock:(void(^)()) didAddRow{ 330 | BOOL found = NO; 331 | NSInteger startingRow = *currentRow; 332 | for(NSInteger j = startingRow; j < reticleMatrix.count; j++){ 333 | NSMutableArray *row = reticleMatrix[j]; 334 | for(NSInteger i = (j== startingRow? *currentColumn+1: 0); i < row.count; i++){ 335 | MatrixElement *element = row[i]; 336 | if(CGRectIsEmpty(element.frame)){ 337 | *currentColumn = i; 338 | found = YES; 339 | break; 340 | } 341 | } 342 | if(!found){ 343 | *currentRow += 1; 344 | *currentColumn = 0; 345 | 346 | if(didAddRow) 347 | didAddRow(); 348 | } else 349 | break; 350 | } 351 | } 352 | 353 | -(void) printMatrix:(NSMutableArray *) matrix{ 354 | NSString *description = @"\n"; 355 | for(NSInteger i = 0; i < matrix.count; i++){ 356 | NSMutableArray *row = matrix[i]; 357 | for(NSInteger j = 0; j < row.count; j++){ 358 | MatrixElement *element = row[j]; 359 | description = [description stringByAppendingFormat:@"\t %li", element.indexPath.item]; 360 | } 361 | description = [description stringByAppendingString:@"\n"]; 362 | } 363 | DLog(@"Matrix: %@", description); 364 | } 365 | 366 | -(NSMutableArray *) addRowOfItems:(NSInteger) items{ 367 | NSMutableArray *row = [NSMutableArray new]; 368 | for(NSInteger i = 0; i < items; i++){ 369 | [row addObject:[MatrixElement new]]; 370 | } 371 | 372 | return row; 373 | } 374 | 375 | -(NSArray *)layoutAttributesForElementsInRect:(CGRect)rect{ 376 | NSMutableArray *layoutAttributes = [NSMutableArray array]; 377 | 378 | for (NSInteger section = 0, n = [self.collectionView numberOfSections]; section < n; section++) { 379 | NSIndexPath *sectionIndexPath = [NSIndexPath indexPathForItem:0 inSection:section]; 380 | 381 | UICollectionViewLayoutAttributes *headerAttributes = [self layoutAttributesForSupplementaryViewOfKind: UICollectionElementKindSectionHeader atIndexPath:sectionIndexPath]; 382 | 383 | if (!CGSizeEqualToSize(headerAttributes.frame.size, CGSizeZero) && CGRectIntersectsRect(headerAttributes.frame, rect)){ 384 | [layoutAttributes addObject:headerAttributes]; 385 | } 386 | 387 | /* It is simpler... but a lot lower!! 388 | for (int i = 0; i < [self.collectionView numberOfItemsInSection:section]; i++) { 389 | NSIndexPath *indexPath = [NSIndexPath indexPathForItem:i inSection:section]; 390 | UICollectionViewLayoutAttributes *attributes = [self layoutAttributesForItemAtIndexPath:indexPath]; 391 | if (CGRectIntersectsRect(rect, attributes.frame)) { 392 | [layoutAttributes addObject:attributes]; 393 | } 394 | }*/ 395 | if([self.collectionView numberOfItemsInSection:section]){ 396 | //Binary algorithm to find matching rects! ^_^ A LOT faster. 397 | NSInteger mid = [self.collectionView numberOfItemsInSection:section]/2; 398 | NSInteger firstMatch = NSNotFound; 399 | 400 | NSInteger left = 0; 401 | NSInteger right = [self.collectionView numberOfItemsInSection:section]; 402 | 403 | do { 404 | NSIndexPath *indexPath = [NSIndexPath indexPathForItem:mid inSection:section]; 405 | UICollectionViewLayoutAttributes *attributes = [self layoutAttributesForItemAtIndexPath:indexPath]; 406 | 407 | if (CGRectIntersectsRect(rect, attributes.frame)) { 408 | firstMatch = mid; 409 | } else { 410 | if(attributes.frame.origin.y >= CGRectGetMaxY(rect)){ 411 | right = mid-1; 412 | } else if(CGRectGetMaxY(attributes.frame) <= rect.origin.y){ 413 | left = mid+1; 414 | } 415 | 416 | mid = (left+right)/2; 417 | } 418 | } while (mid >= 0 && mid < [self.collectionView numberOfItemsInSection:section] && firstMatch == NSNotFound && left < right); 419 | 420 | if(firstMatch != NSNotFound){ 421 | //left part 422 | NSInteger killCount = 15; 423 | for(NSInteger j = firstMatch; j >= 0; j--){ 424 | NSIndexPath *indexPath = [NSIndexPath indexPathForItem:j inSection:section]; 425 | UICollectionViewLayoutAttributes *attributes = [self layoutAttributesForItemAtIndexPath:indexPath]; 426 | if (CGRectIntersectsRect(rect, attributes.frame)) { 427 | [layoutAttributes insertObject:attributes atIndex:0]; 428 | } else if(killCount == 0){ 429 | break; 430 | } else { 431 | killCount--; 432 | } 433 | } 434 | 435 | killCount = 15; 436 | 437 | for(NSInteger j = firstMatch+1; j < [self.collectionView numberOfItemsInSection:section]; j++){ 438 | NSIndexPath *indexPath = [NSIndexPath indexPathForItem:j inSection:section]; 439 | UICollectionViewLayoutAttributes *attributes = [self layoutAttributesForItemAtIndexPath:indexPath]; 440 | if (CGRectIntersectsRect(rect, attributes.frame)) { 441 | [layoutAttributes addObject:attributes]; 442 | } else if(killCount == 0){ 443 | break; 444 | } else { 445 | killCount--; 446 | } 447 | } 448 | } 449 | } 450 | 451 | 452 | UICollectionViewLayoutAttributes *footerAttributes = [self layoutAttributesForSupplementaryViewOfKind:UICollectionElementKindSectionFooter atIndexPath:sectionIndexPath]; 453 | 454 | if (! CGSizeEqualToSize(footerAttributes.frame.size, CGSizeZero) && CGRectIntersectsRect(footerAttributes.frame, rect)){ 455 | [layoutAttributes addObject:footerAttributes]; 456 | } 457 | } 458 | 459 | return layoutAttributes; 460 | } 461 | 462 | - (UICollectionViewLayoutAttributes *)layoutAttributesForSupplementaryViewOfKind:(NSString *)kind atIndexPath:(NSIndexPath *)indexPath { 463 | UICollectionViewLayoutAttributes *attributes = [UICollectionViewLayoutAttributes layoutAttributesForSupplementaryViewOfKind:kind withIndexPath:indexPath]; 464 | 465 | if ([kind isEqualToString:UICollectionElementKindSectionHeader]) { 466 | attributes.frame = [self.framesForHeaderSection[@(indexPath.section)] CGRectValue]; 467 | } else if ([kind isEqualToString:UICollectionElementKindSectionFooter]) { 468 | attributes.frame = [self.framesForFooterSection[@(indexPath.section)] CGRectValue]; 469 | } 470 | 471 | // If there is no header or footer, we need to return nil to prevent a crash from UICollectionView private methods. 472 | if(CGRectIsEmpty(attributes.frame)) { 473 | attributes = nil; 474 | } 475 | 476 | return attributes; 477 | } 478 | 479 | -(UICollectionViewLayoutAttributes *)layoutAttributesForItemAtIndexPath:(NSIndexPath *)indexPath{ 480 | return self.attributesForIndexPath[indexPath]; 481 | } 482 | 483 | -(CGSize)collectionViewContentSize{ 484 | return self.contentSize; 485 | } 486 | 487 | -(void)prepareForCollectionViewUpdates:(NSArray *)updateItems{ 488 | for(UICollectionViewUpdateItem *thisUpdate in updateItems){ 489 | NSIndexPath *indexPath = nil; 490 | 491 | if(thisUpdate.updateAction == UICollectionUpdateActionDelete){ 492 | indexPath = [thisUpdate indexPathBeforeUpdate]; 493 | } else if(thisUpdate.updateAction == UICollectionUpdateActionInsert){ 494 | indexPath = [thisUpdate indexPathAfterUpdate]; 495 | } 496 | 497 | NSMutableDictionary *boundedMatrices = nil; 498 | 499 | if(indexPath.section < self.sectionMatrices.count){ 500 | boundedMatrices = self.sectionMatrices[indexPath.section]; 501 | } 502 | 503 | for(NSMutableArray *reticleMatrix in [boundedMatrices allValues]){ 504 | if([reticleMatrix isKindOfClass:[NSMutableArray class]]){ 505 | NSPredicate *predicate = [NSPredicate predicateWithFormat:@"SUBQUERY(SELF.indexPath, $a, $a == %@).@count != 0", indexPath]; 506 | NSMutableArray *row = [[reticleMatrix filteredArrayUsingPredicate:predicate] firstObject]; 507 | if(row){ 508 | NSInteger rowsToDeleteFrom = -1; 509 | NSInteger rowIndex = [reticleMatrix indexOfObject:row]; 510 | for(NSInteger i = rowIndex; i < reticleMatrix.count; i++){ 511 | NSMutableArray *thisRow = reticleMatrix[i]; 512 | NSInteger replacedCount = 0; 513 | for(NSInteger j = 0; j < thisRow.count; j++){ 514 | if([(MatrixElement *)thisRow[j] indexPath].item >= indexPath.item){ 515 | [thisRow replaceObjectAtIndex:j withObject:[MatrixElement new]]; 516 | replacedCount++; 517 | } 518 | } 519 | 520 | if(replacedCount == thisRow.count){ 521 | rowsToDeleteFrom = i; 522 | break; 523 | } 524 | } 525 | 526 | if(rowsToDeleteFrom != -1){ 527 | [reticleMatrix removeObjectsInRange:NSMakeRange(rowsToDeleteFrom, reticleMatrix.count-rowsToDeleteFrom)]; 528 | } 529 | [self printMatrix:reticleMatrix]; 530 | } 531 | } 532 | } 533 | 534 | NSArray *keysToDelete = [[self.attributesForIndexPath allKeys] filteredArrayUsingPredicate:[NSPredicate predicateWithFormat:@"section == %@ && item >= %@", @(indexPath.section), @(indexPath.item)]]; 535 | [self.attributesForIndexPath removeObjectsForKeys:keysToDelete]; 536 | } 537 | 538 | [self invalidateLayout]; 539 | } 540 | 541 | -(void) invalidateLayout{ 542 | [super invalidateLayout]; 543 | 544 | //DLog(@"layout Invalidated"); 545 | } 546 | 547 | @end 548 | -------------------------------------------------------------------------------- /FBLikeLayout Sample/ImageCollectionViewCell.h: -------------------------------------------------------------------------------- 1 | // 2 | // ImageCollectionViewCell.h 3 | // FBLikeLayout Sample 4 | // 5 | // Created by Giuseppe Lanza on 18/01/15. 6 | // Copyright (c) 2015 La Nuova Era. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface ImageCollectionViewCell : UICollectionViewCell 12 | 13 | @property (strong, nonatomic) IBOutlet UIImageView *photoImageView; 14 | 15 | @end 16 | -------------------------------------------------------------------------------- /FBLikeLayout Sample/ImageCollectionViewCell.m: -------------------------------------------------------------------------------- 1 | // 2 | // ImageCollectionViewCell.m 3 | // FBLikeLayout Sample 4 | // 5 | // Created by Giuseppe Lanza on 18/01/15. 6 | // Copyright (c) 2015 La Nuova Era. All rights reserved. 7 | // 8 | 9 | #import "ImageCollectionViewCell.h" 10 | 11 | @implementation ImageCollectionViewCell 12 | 13 | @end 14 | -------------------------------------------------------------------------------- /FBLikeLayout Sample/Images.xcassets/AppIcon.appiconset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "iphone", 5 | "size" : "29x29", 6 | "scale" : "2x" 7 | }, 8 | { 9 | "idiom" : "iphone", 10 | "size" : "29x29", 11 | "scale" : "3x" 12 | }, 13 | { 14 | "idiom" : "iphone", 15 | "size" : "40x40", 16 | "scale" : "2x" 17 | }, 18 | { 19 | "idiom" : "iphone", 20 | "size" : "40x40", 21 | "scale" : "3x" 22 | }, 23 | { 24 | "idiom" : "iphone", 25 | "size" : "60x60", 26 | "scale" : "2x" 27 | }, 28 | { 29 | "idiom" : "iphone", 30 | "size" : "60x60", 31 | "scale" : "3x" 32 | }, 33 | { 34 | "idiom" : "ipad", 35 | "size" : "29x29", 36 | "scale" : "1x" 37 | }, 38 | { 39 | "idiom" : "ipad", 40 | "size" : "29x29", 41 | "scale" : "2x" 42 | }, 43 | { 44 | "idiom" : "ipad", 45 | "size" : "40x40", 46 | "scale" : "1x" 47 | }, 48 | { 49 | "idiom" : "ipad", 50 | "size" : "40x40", 51 | "scale" : "2x" 52 | }, 53 | { 54 | "idiom" : "ipad", 55 | "size" : "76x76", 56 | "scale" : "1x" 57 | }, 58 | { 59 | "idiom" : "ipad", 60 | "size" : "76x76", 61 | "scale" : "2x" 62 | } 63 | ], 64 | "info" : { 65 | "version" : 1, 66 | "author" : "xcode" 67 | } 68 | } -------------------------------------------------------------------------------- /FBLikeLayout Sample/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleExecutable 8 | $(EXECUTABLE_NAME) 9 | CFBundleIdentifier 10 | org.lanuovaera.$(PRODUCT_NAME:rfc1034identifier) 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 | UIInterfaceOrientationLandscapeLeft 37 | UIInterfaceOrientationLandscapeRight 38 | 39 | UISupportedInterfaceOrientations~ipad 40 | 41 | UIInterfaceOrientationPortrait 42 | UIInterfaceOrientationPortraitUpsideDown 43 | UIInterfaceOrientationLandscapeLeft 44 | UIInterfaceOrientationLandscapeRight 45 | 46 | 47 | 48 | -------------------------------------------------------------------------------- /FBLikeLayout Sample/SampleImages.bundle/286812__angry-tiger_p.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gringoireDM/FBLikeLayout/f7ff5c68a9c14f70d74368072bcdf058fad1c6f3/FBLikeLayout Sample/SampleImages.bundle/286812__angry-tiger_p.jpg -------------------------------------------------------------------------------- /FBLikeLayout Sample/SampleImages.bundle/A-tiger-up-close-010.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gringoireDM/FBLikeLayout/f7ff5c68a9c14f70d74368072bcdf058fad1c6f3/FBLikeLayout Sample/SampleImages.bundle/A-tiger-up-close-010.jpg -------------------------------------------------------------------------------- /FBLikeLayout Sample/SampleImages.bundle/Flash207.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gringoireDM/FBLikeLayout/f7ff5c68a9c14f70d74368072bcdf058fad1c6f3/FBLikeLayout Sample/SampleImages.bundle/Flash207.jpg -------------------------------------------------------------------------------- /FBLikeLayout Sample/SampleImages.bundle/Maltese_Tiger.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gringoireDM/FBLikeLayout/f7ff5c68a9c14f70d74368072bcdf058fad1c6f3/FBLikeLayout Sample/SampleImages.bundle/Maltese_Tiger.jpg -------------------------------------------------------------------------------- /FBLikeLayout Sample/SampleImages.bundle/Project_Tiger.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gringoireDM/FBLikeLayout/f7ff5c68a9c14f70d74368072bcdf058fad1c6f3/FBLikeLayout Sample/SampleImages.bundle/Project_Tiger.jpg -------------------------------------------------------------------------------- /FBLikeLayout Sample/SampleImages.bundle/Siberian_Tiger_by_Malene_Th.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gringoireDM/FBLikeLayout/f7ff5c68a9c14f70d74368072bcdf058fad1c6f3/FBLikeLayout Sample/SampleImages.bundle/Siberian_Tiger_by_Malene_Th.jpg -------------------------------------------------------------------------------- /FBLikeLayout Sample/SampleImages.bundle/South-China-Tiger.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gringoireDM/FBLikeLayout/f7ff5c68a9c14f70d74368072bcdf058fad1c6f3/FBLikeLayout Sample/SampleImages.bundle/South-China-Tiger.jpg -------------------------------------------------------------------------------- /FBLikeLayout Sample/SampleImages.bundle/TiGer-tigers-19955050-900-714.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gringoireDM/FBLikeLayout/f7ff5c68a9c14f70d74368072bcdf058fad1c6f3/FBLikeLayout Sample/SampleImages.bundle/TiGer-tigers-19955050-900-714.jpg -------------------------------------------------------------------------------- /FBLikeLayout Sample/SampleImages.bundle/Tiger-640x433.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gringoireDM/FBLikeLayout/f7ff5c68a9c14f70d74368072bcdf058fad1c6f3/FBLikeLayout Sample/SampleImages.bundle/Tiger-640x433.jpg -------------------------------------------------------------------------------- /FBLikeLayout Sample/SampleImages.bundle/Tiger-Face-770x400.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gringoireDM/FBLikeLayout/f7ff5c68a9c14f70d74368072bcdf058fad1c6f3/FBLikeLayout Sample/SampleImages.bundle/Tiger-Face-770x400.jpg -------------------------------------------------------------------------------- /FBLikeLayout Sample/SampleImages.bundle/Tiger-tigers-32293802-500-627.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gringoireDM/FBLikeLayout/f7ff5c68a9c14f70d74368072bcdf058fad1c6f3/FBLikeLayout Sample/SampleImages.bundle/Tiger-tigers-32293802-500-627.jpg -------------------------------------------------------------------------------- /FBLikeLayout Sample/SampleImages.bundle/Tiger2.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gringoireDM/FBLikeLayout/f7ff5c68a9c14f70d74368072bcdf058fad1c6f3/FBLikeLayout Sample/SampleImages.bundle/Tiger2.jpg -------------------------------------------------------------------------------- /FBLikeLayout Sample/SampleImages.bundle/arrow-poster.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gringoireDM/FBLikeLayout/f7ff5c68a9c14f70d74368072bcdf058fad1c6f3/FBLikeLayout Sample/SampleImages.bundle/arrow-poster.jpg -------------------------------------------------------------------------------- /FBLikeLayout Sample/SampleImages.bundle/flash_by_rattledmachine-d62oesg.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gringoireDM/FBLikeLayout/f7ff5c68a9c14f70d74368072bcdf058fad1c6f3/FBLikeLayout Sample/SampleImages.bundle/flash_by_rattledmachine-d62oesg.jpg -------------------------------------------------------------------------------- /FBLikeLayout Sample/SampleImages.bundle/siberian_tiger_1.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gringoireDM/FBLikeLayout/f7ff5c68a9c14f70d74368072bcdf058fad1c6f3/FBLikeLayout Sample/SampleImages.bundle/siberian_tiger_1.jpg -------------------------------------------------------------------------------- /FBLikeLayout Sample/SampleImages.bundle/snow-tiger.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gringoireDM/FBLikeLayout/f7ff5c68a9c14f70d74368072bcdf058fad1c6f3/FBLikeLayout Sample/SampleImages.bundle/snow-tiger.jpg -------------------------------------------------------------------------------- /FBLikeLayout Sample/SampleImages.bundle/the-flash-artwork-18.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gringoireDM/FBLikeLayout/f7ff5c68a9c14f70d74368072bcdf058fad1c6f3/FBLikeLayout Sample/SampleImages.bundle/the-flash-artwork-18.jpg -------------------------------------------------------------------------------- /FBLikeLayout Sample/SampleImages.bundle/theme-tigers.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gringoireDM/FBLikeLayout/f7ff5c68a9c14f70d74368072bcdf058fad1c6f3/FBLikeLayout Sample/SampleImages.bundle/theme-tigers.jpg -------------------------------------------------------------------------------- /FBLikeLayout Sample/SampleImages.bundle/tiger_by_gregchapin-d5i53qs.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gringoireDM/FBLikeLayout/f7ff5c68a9c14f70d74368072bcdf058fad1c6f3/FBLikeLayout Sample/SampleImages.bundle/tiger_by_gregchapin-d5i53qs.png -------------------------------------------------------------------------------- /FBLikeLayout Sample/SampleImages.bundle/tiger_free.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gringoireDM/FBLikeLayout/f7ff5c68a9c14f70d74368072bcdf058fad1c6f3/FBLikeLayout Sample/SampleImages.bundle/tiger_free.jpg -------------------------------------------------------------------------------- /FBLikeLayout Sample/SampleImages.bundle/tumblr_m0sacwHAsz1r9xp88o1_500.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gringoireDM/FBLikeLayout/f7ff5c68a9c14f70d74368072bcdf058fad1c6f3/FBLikeLayout Sample/SampleImages.bundle/tumblr_m0sacwHAsz1r9xp88o1_500.jpg -------------------------------------------------------------------------------- /FBLikeLayout Sample/ViewController.h: -------------------------------------------------------------------------------- 1 | // 2 | // ViewController.h 3 | // FBLikeLayout Sample 4 | // 5 | // Created by Giuseppe Lanza on 18/01/15. 6 | // Copyright (c) 2015 La Nuova Era. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface ViewController : UIViewController 12 | 13 | 14 | @end 15 | 16 | -------------------------------------------------------------------------------- /FBLikeLayout Sample/ViewController.m: -------------------------------------------------------------------------------- 1 | // 2 | // ViewController.m 3 | // FBLikeLayout Sample 4 | // 5 | // Created by Giuseppe Lanza on 18/01/15. 6 | // Copyright (c) 2015 La Nuova Era. All rights reserved. 7 | // 8 | 9 | #import "ViewController.h" 10 | #import "FBLikeLayout.h" 11 | #import "ImageCollectionViewCell.h" 12 | 13 | @interface ViewController () 14 | 15 | @property (strong, nonatomic) IBOutlet UICollectionView *collectionView; 16 | @property (nonatomic, strong) NSMutableArray * sourceArray; 17 | @property (nonatomic, strong) NSMutableArray * sourceArray_bis; 18 | 19 | @end 20 | 21 | @implementation ViewController 22 | 23 | -(NSString *) sampleImagesBundlePath{ 24 | return [[NSBundle mainBundle] pathForResource:@"SampleImages" ofType:@"bundle"]; 25 | } 26 | 27 | -(NSMutableArray *) sourceArray { 28 | if(!_sourceArray){ 29 | NSString *path = [self sampleImagesBundlePath]; 30 | _sourceArray = [[[NSFileManager defaultManager] contentsOfDirectoryAtPath:path error:nil] mutableCopy]; 31 | } 32 | 33 | return _sourceArray; 34 | } 35 | 36 | -(NSMutableArray *) sourceArray_bis { 37 | if(!_sourceArray_bis){ 38 | NSString *path = [self sampleImagesBundlePath]; 39 | _sourceArray_bis = [[[NSFileManager defaultManager] contentsOfDirectoryAtPath:path error:nil] mutableCopy]; 40 | } 41 | 42 | return _sourceArray_bis; 43 | } 44 | 45 | -(void)viewDidLayoutSubviews{ 46 | [super viewDidLayoutSubviews]; 47 | 48 | if(![self.collectionView.collectionViewLayout isKindOfClass:[FBLikeLayout class]]){ 49 | FBLikeLayout *layout = [FBLikeLayout new]; 50 | layout.minimumInteritemSpacing = 4; 51 | layout.singleCellWidth = (MIN(self.collectionView.bounds.size.width, self.collectionView.bounds.size.height)-self.collectionView.contentInset.left-self.collectionView.contentInset.right-8)/3.0; 52 | layout.maxCellSpace = 3; 53 | layout.forceCellWidthForMinimumInteritemSpacing = YES; 54 | layout.fullImagePercentageOfOccurrency = 50; 55 | self.collectionView.collectionViewLayout = layout; 56 | 57 | [self.collectionView reloadData]; 58 | } else { 59 | //[self.collectionView.collectionViewLayout invalidateLayout]; 60 | } 61 | } 62 | 63 | - (void)viewDidLoad { 64 | [super viewDidLoad]; 65 | // Do any additional setup after loading the view, typically from a nib. 66 | self.title = @"FBLikeLayout"; 67 | 68 | self.collectionView.contentInset = UIEdgeInsetsMake(4, 4, 4, 4); 69 | [self.collectionView registerClass:[UICollectionReusableView class] forSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:@"identifier"]; 70 | [self.collectionView registerClass:[UICollectionReusableView class] forSupplementaryViewOfKind:UICollectionElementKindSectionFooter withReuseIdentifier:@"identifier"]; 71 | } 72 | 73 | - (void)didReceiveMemoryWarning { 74 | [super didReceiveMemoryWarning]; 75 | // Dispose of any resources that can be recreated. 76 | } 77 | 78 | - (IBAction)addItemAction:(id)sender { 79 | NSInteger position = 3; 80 | NSString *objectToAdd = self.sourceArray[arc4random()%self.sourceArray.count]; 81 | [self.sourceArray insertObject:objectToAdd atIndex:position]; 82 | NSLog(@"Insert position = %li", (long)position); 83 | 84 | [self.collectionView performBatchUpdates:^{ 85 | [self.collectionView insertItemsAtIndexPaths:@[[NSIndexPath indexPathForItem:position inSection:0]]]; 86 | } completion:nil]; 87 | 88 | } 89 | 90 | #pragma mark - CollectionView DataSource 91 | 92 | -(NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView{ 93 | return 3; 94 | } 95 | 96 | -(NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{ 97 | return section == 0? self.sourceArray.count: self.sourceArray_bis.count; 98 | } 99 | 100 | -(CGSize) collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout referenceSizeForFooterInSection:(NSInteger)section{ 101 | return CGSizeMake(self.collectionView.bounds.size.width, 30); 102 | } 103 | 104 | -(CGSize) collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout referenceSizeForHeaderInSection:(NSInteger)section{ 105 | return CGSizeMake(self.collectionView.bounds.size.width, 30); 106 | } 107 | 108 | -(UICollectionReusableView *) collectionView:(UICollectionView *)collectionView viewForSupplementaryElementOfKind:(NSString *)kind atIndexPath:(NSIndexPath *)indexPath{ 109 | UICollectionReusableView *view = [collectionView dequeueReusableSupplementaryViewOfKind:kind withReuseIdentifier:@"identifier" forIndexPath:indexPath]; 110 | 111 | if(!view) 112 | view = [[UICollectionReusableView alloc] init]; 113 | view.backgroundColor = [UIColor whiteColor]; 114 | 115 | return view; 116 | } 117 | 118 | -(UICollectionViewCell *) collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{ 119 | ImageCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"photoCell" forIndexPath:indexPath]; 120 | cell.backgroundColor = [UIColor whiteColor]; 121 | 122 | NSString *imagePath = [[self sampleImagesBundlePath] stringByAppendingPathComponent:[indexPath.section == 0? self.sourceArray: self.sourceArray_bis objectAtIndex:indexPath.item]]; 123 | 124 | cell.photoImageView.image = [UIImage imageWithContentsOfFile:imagePath]; 125 | 126 | return cell; 127 | } 128 | 129 | 130 | -(CGSize) collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath{ 131 | 132 | NSString *imagePath = [[self sampleImagesBundlePath] stringByAppendingPathComponent:self.sourceArray[indexPath.item]]; 133 | CGSize finalSize = [UIImage imageWithContentsOfFile:imagePath].size; 134 | 135 | return finalSize; 136 | } 137 | 138 | @end 139 | -------------------------------------------------------------------------------- /FBLikeLayout Sample/main.m: -------------------------------------------------------------------------------- 1 | // 2 | // main.m 3 | // FBLikeLayout Sample 4 | // 5 | // Created by Giuseppe Lanza on 18/01/15. 6 | // Copyright (c) 2015 La Nuova Era. All rights reserved. 7 | // 8 | 9 | #import 10 | #import "AppDelegate.h" 11 | 12 | int main(int argc, char * argv[]) { 13 | @autoreleasepool { 14 | return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class])); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /FBLikeLayout SampleTests/FBLikeLayout_SampleTests.m: -------------------------------------------------------------------------------- 1 | // 2 | // FBLikeLayout_SampleTests.m 3 | // FBLikeLayout SampleTests 4 | // 5 | // Created by Giuseppe Lanza on 18/01/15. 6 | // Copyright (c) 2015 La Nuova Era. All rights reserved. 7 | // 8 | 9 | #import 10 | #import 11 | 12 | @interface FBLikeLayout_SampleTests : XCTestCase 13 | 14 | @end 15 | 16 | @implementation FBLikeLayout_SampleTests 17 | 18 | - (void)setUp { 19 | [super setUp]; 20 | // Put setup code here. This method is called before the invocation of each test method in the class. 21 | } 22 | 23 | - (void)tearDown { 24 | // Put teardown code here. This method is called after the invocation of each test method in the class. 25 | [super tearDown]; 26 | } 27 | 28 | - (void)testExample { 29 | // This is an example of a functional test case. 30 | XCTAssert(YES, @"Pass"); 31 | } 32 | 33 | - (void)testPerformanceExample { 34 | // This is an example of a performance test case. 35 | [self measureBlock:^{ 36 | // Put the code you want to measure the time of here. 37 | }]; 38 | } 39 | 40 | @end 41 | -------------------------------------------------------------------------------- /FBLikeLayout SampleTests/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleExecutable 8 | $(EXECUTABLE_NAME) 9 | CFBundleIdentifier 10 | org.lanuovaera.$(PRODUCT_NAME:rfc1034identifier) 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 | -------------------------------------------------------------------------------- /FBLikeLayout.podspec: -------------------------------------------------------------------------------- 1 | 2 | Pod::Spec.new do |s| 3 | 4 | s.name = "FBLikeLayout" 5 | s.version = "1.2" 6 | s.summary = "A UICollectionView Layout inspired by Facebook photos section." 7 | 8 | s.description = <<-DESC 9 | This is an UICollectionView layout inspired by the photo section of facebook. 10 | This layout loads squared items with randomic full size items. 11 | It works with standard layout delegate methods. No additional custom methods to be implemented. 12 | DESC 13 | 14 | s.license = { :type => 'MIT' } 15 | s.homepage = "https://github.com/gringoireDM/FBLikeLayout.git" 16 | 17 | s.author = { "Giuseppe Lanza" => "gringoire986@gmail.com" } 18 | s.social_media_url = "http://twitter.com/gringoireDM" 19 | s.platform = :ios, '7.0' 20 | s.requires_arc = true 21 | s.source = { :git => "https://github.com/gringoireDM/FBLikeLayout.git", :tag => "1.2" } 22 | 23 | s.source_files = "FBLikeLayout Sample/FBLikeLayout", "FBLikeLayout Sample/FBLikeLayout/*.{h,m}", "FBLikeLayout Sample/FBLikeLayout/**/*.{h,m}" 24 | 25 | end 26 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2014 Giuseppe Lanza 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 | FBLikeLayout 2 | ============= 3 | 4 | This is an UICollectionView layout inspired by the photo section of facebook. 5 | This layout loads squared items with randomic full size items. 6 | It works with standard layout delegate methods. No additional custom methods to be implemented. 7 | 8 | ![Screenshot1](./screenshot.png) 9 | 10 | ![Screenshot2](./screenshot2.png) 11 | 12 | ##FBLikeLayout 13 | You can use this layout in your project by adding to your podfile: 14 |
pod 'FBLikeLayout'
15 | 16 | ##Usage 17 | 18 | Just allocate a new `FBLikeLayout`, then customize the few properties this layout comes with 19 | 20 | ```objc 21 | FBLikeLayout *layout = [FBLikeLayout new]; 22 | 23 | //in this case we want 3 cells per row, maximum. This is also the default value if you do not customize the layout.singleCellWidth property 24 | CGFloat cellWidth = (MIN(self.collectionView.bounds.size.width, self.collectionView.bounds.size.height)-self.collectionView.contentInset.left-self.collectionView.contentInset.right-8)/3.0; 25 | 26 | layout.minimumInteritemSpacing = 4; 27 | layout.singleCellWidth = cellWidth; 28 | layout.maxCellSpace = 3; //for full size cells, this parameter determines the max cell space 29 | 30 | //if you want the items size to be forced in order to have the minimumInteritemSpacing always respected. Otherwise the interitem spacing will be adapted in order to cover the complete row with cells 31 | layout.forceCellWidthForMinimumInteritemSpacing = YES; 32 | layout.fullImagePercentageOfOccurrency = 25; //this percent value determines how many times randomly the item will be full size. 33 | 34 | self.collectionView.collectionViewLayout = layout; 35 | ``` 36 | 37 | Then just implement the UICollectionViewDelegateFlowLayout method: 38 | ```objc 39 | -(CGSize) collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath 40 | ``` 41 | -------------------------------------------------------------------------------- /screenshot.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gringoireDM/FBLikeLayout/f7ff5c68a9c14f70d74368072bcdf058fad1c6f3/screenshot.png -------------------------------------------------------------------------------- /screenshot2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gringoireDM/FBLikeLayout/f7ff5c68a9c14f70d74368072bcdf058fad1c6f3/screenshot2.png --------------------------------------------------------------------------------