├── MetroCollectionLayoutSample ├── MetroCollectionLayoutSample.xcodeproj │ ├── xcuserdata │ │ └── karthik.xcuserdatad │ │ │ ├── xcdebugger │ │ │ └── Breakpoints_v2.xcbkptlist │ │ │ └── xcschemes │ │ │ ├── xcschememanagement.plist │ │ │ └── MetroCollectionLayoutSample.xcscheme │ ├── project.xcworkspace │ │ ├── contents.xcworkspacedata │ │ ├── xcuserdata │ │ │ └── karthik.xcuserdatad │ │ │ │ ├── UserInterfaceState.xcuserstate │ │ │ │ └── WorkspaceSettings.xcsettings │ │ └── xcshareddata │ │ │ └── MetroCollectionLayoutSample.xccheckout │ └── project.pbxproj ├── MetroCollectionLayoutSample │ ├── Views │ │ ├── MetroCollectionViewCell.m │ │ └── MetroCollectionViewCell.h │ ├── AppDelegate.h │ ├── main.m │ ├── ViewController.h │ ├── Images.xcassets │ │ └── AppIcon.appiconset │ │ │ └── Contents.json │ ├── Info.plist │ ├── AppDelegate.m │ ├── Base.lproj │ │ ├── LaunchScreen.xib │ │ └── Main.storyboard │ └── ViewController.m ├── MetroCollectionLayoutSampleTests │ ├── Info.plist │ └── MetroCollectionLayoutSampleTests.m └── MetroCollectionLayout │ ├── MetroCollectionLayout.h │ └── MetroCollectionLayout.m ├── README.md ├── LICENSE └── MetroCollectionLayout ├── MetroCollectionLayout.h └── MetroCollectionLayout.m /MetroCollectionLayoutSample/MetroCollectionLayoutSample.xcodeproj/xcuserdata/karthik.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | -------------------------------------------------------------------------------- /MetroCollectionLayoutSample/MetroCollectionLayoutSample.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /MetroCollectionLayoutSample/MetroCollectionLayoutSample.xcodeproj/project.xcworkspace/xcuserdata/karthik.xcuserdatad/UserInterfaceState.xcuserstate: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/karticodes/MetroCollectionLayout-ObjC/HEAD/MetroCollectionLayoutSample/MetroCollectionLayoutSample.xcodeproj/project.xcworkspace/xcuserdata/karthik.xcuserdatad/UserInterfaceState.xcuserstate -------------------------------------------------------------------------------- /MetroCollectionLayoutSample/MetroCollectionLayoutSample/Views/MetroCollectionViewCell.m: -------------------------------------------------------------------------------- 1 | // 2 | // MetroCollectionViewCell.m 3 | // MetroCollectionLayoutSample 4 | // 5 | // Created by Karthik M R on 16/04/15. 6 | // Copyright (c) 2015 Karti Codes. All rights reserved. 7 | // 8 | 9 | #import "MetroCollectionViewCell.h" 10 | 11 | @implementation MetroCollectionViewCell 12 | 13 | @end 14 | -------------------------------------------------------------------------------- /MetroCollectionLayoutSample/MetroCollectionLayoutSample/AppDelegate.h: -------------------------------------------------------------------------------- 1 | // 2 | // AppDelegate.h 3 | // MetroCollectionLayoutSample 4 | // 5 | // Created by Karthik M R on 16/04/15. 6 | // Copyright (c) 2015 Karti Codes. 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 | -------------------------------------------------------------------------------- /MetroCollectionLayoutSample/MetroCollectionLayoutSample/Views/MetroCollectionViewCell.h: -------------------------------------------------------------------------------- 1 | // 2 | // MetroCollectionViewCell.h 3 | // MetroCollectionLayoutSample 4 | // 5 | // Created by Karthik M R on 16/04/15. 6 | // Copyright (c) 2015 Karti Codes. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface MetroCollectionViewCell : UICollectionViewCell 12 | @property (weak, nonatomic) IBOutlet UILabel *titleLabel; 13 | 14 | @end 15 | -------------------------------------------------------------------------------- /MetroCollectionLayoutSample/MetroCollectionLayoutSample/main.m: -------------------------------------------------------------------------------- 1 | // 2 | // main.m 3 | // MetroCollectionLayoutSample 4 | // 5 | // Created by Karthik M R on 16/04/15. 6 | // Copyright (c) 2015 Karti Codes. 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 | -------------------------------------------------------------------------------- /MetroCollectionLayoutSample/MetroCollectionLayoutSample.xcodeproj/project.xcworkspace/xcuserdata/karthik.xcuserdatad/WorkspaceSettings.xcsettings: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | HasAskedToTakeAutomaticSnapshotBeforeSignificantChanges 6 | 7 | SnapshotAutomaticallyBeforeSignificantChanges 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /MetroCollectionLayoutSample/MetroCollectionLayoutSample/ViewController.h: -------------------------------------------------------------------------------- 1 | // 2 | // ViewController.h 3 | // MetroCollectionLayoutSample 4 | // 5 | // Created by Karthik M R on 16/04/15. 6 | // Copyright (c) 2015 Karti Codes. All rights reserved. 7 | // 8 | 9 | #import 10 | #import "MetroCollectionLayout.h" 11 | #import "MetroCollectionViewCell.h" 12 | 13 | @interface ViewController : UIViewController 14 | 15 | @property (weak, nonatomic) IBOutlet UICollectionView *collectionView; 16 | 17 | 18 | @end 19 | 20 | -------------------------------------------------------------------------------- /MetroCollectionLayoutSample/MetroCollectionLayoutSample.xcodeproj/xcuserdata/karthik.xcuserdatad/xcschemes/xcschememanagement.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | SchemeUserState 6 | 7 | MetroCollectionLayoutSample.xcscheme 8 | 9 | orderHint 10 | 0 11 | 12 | 13 | SuppressBuildableAutocreation 14 | 15 | 255A296F1AE02CF6002B62BA 16 | 17 | primary 18 | 19 | 20 | 255A29881AE02CF6002B62BA 21 | 22 | primary 23 | 24 | 25 | 26 | 27 | 28 | -------------------------------------------------------------------------------- /MetroCollectionLayoutSample/MetroCollectionLayoutSampleTests/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleExecutable 8 | $(EXECUTABLE_NAME) 9 | CFBundleIdentifier 10 | com.karticodes.$(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 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # MetroCollectionLayout 2 | #### Objective C 3 | A metro style collection layout for iOS - Objective C 4 | 5 | MetroCollectionLayout is an ready to use, universal collection view layout for iOS(iPhone and iPad). It provides the completely customizable layout with delegates to manage the layout sytles. 6 | 7 | #### *iPhone Layout* 8 | ![alt tag](https://raw.githubusercontent.com/karticodes/MetroCollectionLayout/images/MetroCollectionLayoutSample/Layout_Phone.jpg) 9 | 10 | #### *iPad Layout* 11 | ![alt tag](https://raw.githubusercontent.com/karticodes/MetroCollectionLayout/images/MetroCollectionLayoutSample/Layout_Pad.png) 12 | 13 | # Installation 14 | Set the collection View Layout as MetroCollectionLayout object. 15 | > self.collectionView.collectionViewLayout = [[MetroCollectionLayout alloc] initWithDelegate:self]; 16 | 17 | Conform to the **MetroCollectionLayoutDelegate** protocol and implement the optional delegate methods as per the need. 18 | 19 | Contact karticodes@gmail.com for custom layouts. 20 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2015 Karthik Ramesh 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 | -------------------------------------------------------------------------------- /MetroCollectionLayoutSample/MetroCollectionLayoutSampleTests/MetroCollectionLayoutSampleTests.m: -------------------------------------------------------------------------------- 1 | // 2 | // MetroCollectionLayoutSampleTests.m 3 | // MetroCollectionLayoutSampleTests 4 | // 5 | // Created by Karthik M R on 16/04/15. 6 | // Copyright (c) 2015 Karti Codes. All rights reserved. 7 | // 8 | 9 | #import 10 | #import 11 | 12 | @interface MetroCollectionLayoutSampleTests : XCTestCase 13 | 14 | @end 15 | 16 | @implementation MetroCollectionLayoutSampleTests 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 | -------------------------------------------------------------------------------- /MetroCollectionLayoutSample/MetroCollectionLayoutSample/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 | } -------------------------------------------------------------------------------- /MetroCollectionLayoutSample/MetroCollectionLayoutSample.xcodeproj/project.xcworkspace/xcshareddata/MetroCollectionLayoutSample.xccheckout: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | IDESourceControlProjectFavoriteDictionaryKey 6 | 7 | IDESourceControlProjectIdentifier 8 | C1F00E14-3379-4ABB-950F-311C0D4889B1 9 | IDESourceControlProjectName 10 | MetroCollectionLayoutSample 11 | IDESourceControlProjectOriginsDictionary 12 | 13 | ABA7FEE14C111872484C13F8E401E415429B97D7 14 | https://github.com/karthikmrt/MetroCollectionLayout.git 15 | 16 | IDESourceControlProjectPath 17 | MetroCollectionLayoutSample/MetroCollectionLayoutSample.xcodeproj 18 | IDESourceControlProjectRelativeInstallPathDictionary 19 | 20 | ABA7FEE14C111872484C13F8E401E415429B97D7 21 | ../../.. 22 | 23 | IDESourceControlProjectURL 24 | https://github.com/karthikmrt/MetroCollectionLayout.git 25 | IDESourceControlProjectVersion 26 | 111 27 | IDESourceControlProjectWCCIdentifier 28 | ABA7FEE14C111872484C13F8E401E415429B97D7 29 | IDESourceControlProjectWCConfigurations 30 | 31 | 32 | IDESourceControlRepositoryExtensionIdentifierKey 33 | public.vcs.git 34 | IDESourceControlWCCIdentifierKey 35 | ABA7FEE14C111872484C13F8E401E415429B97D7 36 | IDESourceControlWCCName 37 | MetroCollectionLayout 38 | 39 | 40 | 41 | 42 | -------------------------------------------------------------------------------- /MetroCollectionLayoutSample/MetroCollectionLayoutSample/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleExecutable 8 | $(EXECUTABLE_NAME) 9 | CFBundleIdentifier 10 | com.karticodes.$(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 | UIStatusBarHidden 34 | 35 | UISupportedInterfaceOrientations 36 | 37 | UIInterfaceOrientationPortrait 38 | UIInterfaceOrientationLandscapeLeft 39 | UIInterfaceOrientationLandscapeRight 40 | 41 | UISupportedInterfaceOrientations~ipad 42 | 43 | UIInterfaceOrientationPortrait 44 | UIInterfaceOrientationPortraitUpsideDown 45 | UIInterfaceOrientationLandscapeLeft 46 | UIInterfaceOrientationLandscapeRight 47 | 48 | UIViewControllerBasedStatusBarAppearance 49 | 50 | 51 | 52 | -------------------------------------------------------------------------------- /MetroCollectionLayoutSample/MetroCollectionLayoutSample/AppDelegate.m: -------------------------------------------------------------------------------- 1 | // 2 | // AppDelegate.m 3 | // MetroCollectionLayoutSample 4 | // 5 | // Created by Karthik M R on 16/04/15. 6 | // Copyright (c) 2015 Karti Codes. 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 | -------------------------------------------------------------------------------- /MetroCollectionLayout/MetroCollectionLayout.h: -------------------------------------------------------------------------------- 1 | // 2 | // MetroFlowLayout.h 3 | // FlowLayoutSample 4 | // 5 | // Created by Karthik on 3/19/15. 6 | // Copyright (c) 2015 Karthik. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | /** 12 | * Enum to represent the wide cell direction 13 | */ 14 | typedef NS_ENUM(NSUInteger, MetroCollectionLayoutDirection) { 15 | MetroCollectionLayoutDirectionLeft, 16 | MetroCollectionLayoutDirectionRight 17 | }; 18 | 19 | @class MetroCollectionLayout; 20 | 21 | @protocol MetroCollectionLayoutDelegate 22 | 23 | @optional 24 | 25 | /** 26 | * Optional Delegate - If not implemented, half the width of collectionview is taken. 27 | * gets the wide cell width to be used throughout the layout. 28 | * @return CGFloat representing the wide cell width. 29 | */ 30 | -(CGFloat)wideCellWidthForCollectionView:(UICollectionView *)collectionView andLayout:(MetroCollectionLayout *)collectionViewLayout; 31 | 32 | /** 33 | * Should be an odd positive integer. 34 | * Optional Delegate - If not implemented, 3 is taken for iPhone and 5 is taken for iPad. 35 | * gets the number of items per group(number of collection items in the wide cell range) to be used in the layout. 36 | * @return NSInteger representing number of items per group. 37 | */ 38 | -(NSInteger)numberOfItemsPerGroupForCollectionView:(UICollectionView *)collectionView andLayout:(MetroCollectionLayout *)collectionViewLayout; 39 | 40 | /** 41 | * Optional Delegate - If not implemented, self.shouldAutoAlign = NO; 42 | * Determines whether the layout to be autoaligned, if items count per section is lesser than expected in order to avoid the empty 43 | * spaces. 44 | * @return BOOL representing the auto alignment. 45 | */ 46 | -(BOOL)shouldAutoAlignCollectionView:(UICollectionView *)collectionView; 47 | 48 | /** 49 | * Optional Delegate - If not implemented, taken alternatively starting from MetroCollectionLayoutDirectionLeft. 50 | * gets the direction in which the wide cell to be aligned. If MetroCollectionLayoutDirectionLeft, the wide cell starts from left. 51 | * @return MetroCollectionLayoutDirection representing the wide cell direction. 52 | */ 53 | - (MetroCollectionLayoutDirection)collectionView:(UICollectionView *)collectionView layout:(MetroCollectionLayout *)collectionViewLayout directionForGroup:(NSInteger)group inSection:(NSInteger)section; 54 | 55 | /** 56 | * Optional Delegate - If not implemented, the value taken as 0. 57 | * gets the estimated size of Section header. 58 | * @return CGSize representing the estimated size of Section Header. 59 | */ 60 | - (CGSize)collectionView:(UICollectionView *)collectionView layout:(MetroCollectionLayout *)collectionViewLayout estimatedSizeForHeaderInSection:(NSInteger)section; 61 | 62 | /** 63 | * Optional Delegate - If not implemented, the value taken as 0. 64 | * gets the estimated size of Section footer. 65 | * @return CGSize representing the estimated size of Section footer. 66 | */ 67 | - (CGSize)collectionView:(UICollectionView *)collectionView layout:(MetroCollectionLayout *)collectionViewLayout estimatedSizeForFooterInSection:(NSInteger)section; 68 | 69 | @end 70 | 71 | @interface MetroCollectionLayout : UICollectionViewLayout 72 | 73 | @property (nonatomic, weak) id delegate; 74 | - (instancetype)initWithDelegate:(id)delegate; 75 | 76 | @end 77 | -------------------------------------------------------------------------------- /MetroCollectionLayoutSample/MetroCollectionLayout/MetroCollectionLayout.h: -------------------------------------------------------------------------------- 1 | // 2 | // MetroFlowLayout.h 3 | // MetroCollectionLayoutSample 4 | // 5 | // Created by Karthik on 3/19/15. 6 | // Copyright (c) 2015 Karthik. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | /** 12 | * Enum to represent the wide cell direction 13 | */ 14 | typedef NS_ENUM(NSUInteger, MetroCollectionLayoutDirection) { 15 | MetroCollectionLayoutDirectionLeft, 16 | MetroCollectionLayoutDirectionRight 17 | }; 18 | 19 | @class MetroCollectionLayout; 20 | 21 | @protocol MetroCollectionLayoutDelegate 22 | 23 | @optional 24 | 25 | /** 26 | * Optional Delegate - If not implemented, half the width of collectionview is taken. 27 | * gets the wide cell width to be used throughout the layout. 28 | * @return CGFloat representing the wide cell width. 29 | */ 30 | -(CGFloat)wideCellWidthForCollectionView:(UICollectionView *)collectionView andLayout:(MetroCollectionLayout *)collectionViewLayout; 31 | 32 | /** 33 | * Should be an odd positive integer. 34 | * Optional Delegate - If not implemented, 3 is taken for iPhone and 5 is taken for iPad. 35 | * gets the number of items per group(number of collection items in the wide cell range) to be used in the layout. 36 | * @return NSInteger representing number of items per group. 37 | */ 38 | -(NSInteger)numberOfItemsPerGroupForCollectionView:(UICollectionView *)collectionView andLayout:(MetroCollectionLayout *)collectionViewLayout; 39 | 40 | /** 41 | * Optional Delegate - If not implemented, self.shouldAutoAlign = NO; 42 | * Determines whether the layout to be autoaligned, if items count per section is lesser than expected in order to avoid the empty 43 | * spaces. 44 | * @return BOOL representing the auto alignment. 45 | */ 46 | -(BOOL)shouldAutoAlignCollectionView:(UICollectionView *)collectionView; 47 | 48 | /** 49 | * Optional Delegate - If not implemented, taken alternatively starting from MetroCollectionLayoutDirectionLeft. 50 | * gets the direction in which the wide cell to be aligned. If MetroCollectionLayoutDirectionLeft, the wide cell starts from left. 51 | * @return MetroCollectionLayoutDirection representing the wide cell direction. 52 | */ 53 | - (MetroCollectionLayoutDirection)collectionView:(UICollectionView *)collectionView layout:(MetroCollectionLayout *)collectionViewLayout directionForGroup:(NSInteger)group inSection:(NSInteger)section; 54 | 55 | /** 56 | * Optional Delegate - If not implemented, the value taken as 0. 57 | * gets the estimated size of Section header. 58 | * @return CGSize representing the estimated size of Section Header. 59 | */ 60 | - (CGSize)collectionView:(UICollectionView *)collectionView layout:(MetroCollectionLayout *)collectionViewLayout estimatedSizeForHeaderInSection:(NSInteger)section; 61 | 62 | /** 63 | * Optional Delegate - If not implemented, the value taken as 0. 64 | * gets the estimated size of Section footer. 65 | * @return CGSize representing the estimated size of Section footer. 66 | */ 67 | - (CGSize)collectionView:(UICollectionView *)collectionView layout:(MetroCollectionLayout *)collectionViewLayout estimatedSizeForFooterInSection:(NSInteger)section; 68 | 69 | @end 70 | 71 | @interface MetroCollectionLayout : UICollectionViewLayout 72 | 73 | @property (nonatomic, weak) id delegate; 74 | - (instancetype)initWithDelegate:(id)delegate; 75 | 76 | @end 77 | -------------------------------------------------------------------------------- /MetroCollectionLayoutSample/MetroCollectionLayoutSample/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 | -------------------------------------------------------------------------------- /MetroCollectionLayoutSample/MetroCollectionLayoutSample/ViewController.m: -------------------------------------------------------------------------------- 1 | // 2 | // ViewController.m 3 | // MetroCollectionLayoutSample 4 | // 5 | // Created by Karthik M R on 16/04/15. 6 | // Copyright (c) 2015 Karti Codes. All rights reserved. 7 | // 8 | 9 | #import "ViewController.h" 10 | 11 | static NSString *const MetroCollectionCellIdentifier = @"MetroCollectionViewCell"; 12 | static NSString *const MetroCollectionHeaderIdentifier = @"MetroCollectionViewHeader"; 13 | static NSString *const MetroCollectionFooterIdentifier = @"MetroCollectionViewFooter"; 14 | 15 | @interface ViewController () 16 | 17 | @end 18 | 19 | @implementation ViewController 20 | 21 | - (void)viewDidLoad { 22 | [super viewDidLoad]; 23 | // Do any additional setup after loading the view, typically from a nib. 24 | [self initialiseCollectionView]; 25 | } 26 | 27 | - (void)didReceiveMemoryWarning { 28 | [super didReceiveMemoryWarning]; 29 | // Dispose of any resources that can be recreated. 30 | } 31 | 32 | #pragma mark - Initialization 33 | -(void)initialiseCollectionView{ 34 | self.collectionView.collectionViewLayout = [[MetroCollectionLayout alloc] initWithDelegate:self]; 35 | } 36 | 37 | #pragma mark - Collection View Data Source 38 | - (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView{ 39 | return 1; 40 | } 41 | 42 | - (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{ 43 | return 10; 44 | } 45 | 46 | - (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{ 47 | MetroCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:MetroCollectionCellIdentifier forIndexPath:indexPath]; 48 | cell.titleLabel.text = [NSString stringWithFormat:@"%ld", (long)indexPath.row]; 49 | return cell; 50 | } 51 | 52 | #pragma mark - Collection View Delegates 53 | -(UICollectionReusableView *)collectionView:(UICollectionView *)collectionView viewForSupplementaryElementOfKind:(NSString *)kind atIndexPath:(NSIndexPath *)indexPath{ 54 | UICollectionReusableView *supplementaryView; 55 | if ([kind isEqualToString:UICollectionElementKindSectionHeader]) { 56 | supplementaryView = [collectionView dequeueReusableSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:MetroCollectionHeaderIdentifier forIndexPath:indexPath]; 57 | }else{ 58 | supplementaryView = [collectionView dequeueReusableSupplementaryViewOfKind:UICollectionElementKindSectionFooter withReuseIdentifier:MetroCollectionFooterIdentifier forIndexPath:indexPath]; 59 | } 60 | return supplementaryView; 61 | } 62 | 63 | #pragma mark - Metro Collection Layout Delegate 64 | - (CGSize)collectionView:(UICollectionView *)collectionView layout:(MetroCollectionLayout *)collectionViewLayout estimatedSizeForHeaderInSection:(NSInteger)section{ 65 | return CGSizeMake(CGRectGetWidth(collectionView.bounds), 83); 66 | } 67 | 68 | -(CGSize)collectionView:(UICollectionView *)collectionView layout:(MetroCollectionLayout *)collectionViewLayout estimatedSizeForFooterInSection:(NSInteger)section{ 69 | return CGSizeMake(CGRectGetWidth(collectionView.bounds), 83); 70 | } 71 | 72 | -(CGFloat)wideCellWidthForCollectionView:(UICollectionView *)collectionView andLayout:(MetroCollectionLayout *)collectionViewLayout{ 73 | return CGRectGetWidth(self.collectionView.bounds)/2; 74 | } 75 | 76 | -(NSInteger)numberOfItemsPerGroupForCollectionView:(UICollectionView *)collectionView andLayout:(MetroCollectionLayout *)collectionViewLayout{ 77 | return 5; 78 | } 79 | 80 | -(BOOL)shouldAutoAlignCollectionView:(UICollectionView *)collectionView{ 81 | return NO; 82 | } 83 | 84 | - (MetroCollectionLayoutDirection)collectionView:(UICollectionView *)collectionView layout:(MetroCollectionLayout *)collectionViewLayout directionForGroup:(NSInteger)group inSection:(NSInteger)section{ 85 | if (group % 2 == 0) { 86 | return MetroCollectionLayoutDirectionLeft; 87 | } else { 88 | return MetroCollectionLayoutDirectionRight; 89 | } 90 | } 91 | 92 | @end 93 | -------------------------------------------------------------------------------- /MetroCollectionLayoutSample/MetroCollectionLayoutSample.xcodeproj/xcuserdata/karthik.xcuserdatad/xcschemes/MetroCollectionLayoutSample.xcscheme: -------------------------------------------------------------------------------- 1 | 2 | 5 | 8 | 9 | 15 | 21 | 22 | 23 | 29 | 35 | 36 | 37 | 38 | 39 | 44 | 45 | 47 | 53 | 54 | 55 | 56 | 57 | 63 | 64 | 65 | 66 | 75 | 77 | 83 | 84 | 85 | 86 | 87 | 88 | 94 | 96 | 102 | 103 | 104 | 105 | 107 | 108 | 111 | 112 | 113 | -------------------------------------------------------------------------------- /MetroCollectionLayoutSample/MetroCollectionLayoutSample/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 | 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 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 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 | -------------------------------------------------------------------------------- /MetroCollectionLayoutSample/MetroCollectionLayout/MetroCollectionLayout.m: -------------------------------------------------------------------------------- 1 | // 2 | // MetroFlowLayout.m 3 | // MetroCollectionLayoutSample 4 | // 5 | // Created by Karthik on 3/19/15. 6 | // Copyright (c) 2015 Karthik. All rights reserved. 7 | // 8 | 9 | #import "MetroCollectionLayout.h" 10 | 11 | static NSString *const MetroCollectionViewCell = @"MetroCollectionViewCell"; 12 | NSString *const MetroCollectionViewHeader = @"UICollectionElementKindSectionHeader"; 13 | NSString *const MetroCollectionViewFooter = @"UICollectionElementKindSectionFooter"; 14 | 15 | #define isIPhone (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone) 16 | 17 | @interface MetroCollectionLayout() 18 | 19 | @property (nonatomic, strong) NSDictionary *layoutInfoDict; 20 | @property (nonatomic, strong) NSMutableDictionary *sectionHeaderSizes; 21 | @property (nonatomic, strong) NSMutableDictionary *sectionFooterSizes; 22 | 23 | @property (nonatomic, assign) CGFloat wideCellWidth; 24 | @property (nonatomic, assign) CGFloat wideCellHeight; 25 | @property (nonatomic, assign) CGFloat cellWidth; 26 | @property (nonatomic, assign) CGFloat cellHeight; 27 | 28 | @property (nonatomic, readonly) NSInteger numberOfSections; 29 | @property (nonatomic, readonly) NSInteger itemsPerSubRow; 30 | 31 | @property (nonatomic, assign) MetroCollectionLayoutDirection wideCellDirection; 32 | @property (nonatomic, assign) BOOL shouldAutoAlign; 33 | @property (nonatomic, assign) NSInteger numberOfItems; 34 | 35 | @end 36 | 37 | @implementation MetroCollectionLayout 38 | 39 | - (instancetype)initWithDelegate:(id)delegate{ 40 | self = [super init]; 41 | if (self) { 42 | _delegate = delegate; 43 | } 44 | return self; 45 | } 46 | 47 | #pragma mark - Init 48 | 49 | - (void)calculateValues{ 50 | if (_delegate && [_delegate respondsToSelector:@selector(numberOfItemsPerGroupForCollectionView:andLayout:)]) { 51 | _numberOfItems = [_delegate numberOfItemsPerGroupForCollectionView:self.collectionView andLayout:self]; 52 | }else{ 53 | _numberOfItems = (isIPhone)? 3: 5; 54 | } 55 | 56 | if (_delegate && [_delegate respondsToSelector:@selector(wideCellWidthForCollectionView:andLayout:)]) { 57 | _wideCellWidth = [_delegate wideCellWidthForCollectionView:self.collectionView andLayout:self]; 58 | }else{ 59 | _wideCellWidth = (isIPhone)? (2 * CGRectGetWidth(self.collectionView.bounds)/3): ( CGRectGetWidth(self.collectionView.bounds)/2); 60 | } 61 | if (_delegate && [_delegate respondsToSelector:@selector(shouldAutoAlignCollectionView:)]) { 62 | _shouldAutoAlign = [_delegate shouldAutoAlignCollectionView:self.collectionView]; 63 | }else{ 64 | _shouldAutoAlign = NO; 65 | } 66 | } 67 | 68 | - (CGFloat)cellWidth{ 69 | return (CGRectGetWidth([self.collectionView bounds]) - self.wideCellWidth)/self.itemsPerSubRow; 70 | } 71 | 72 | - (NSInteger)itemsPerSubRow{ 73 | return (self.numberOfItems-1)/2; 74 | } 75 | 76 | - (NSInteger)numberOfSections{ 77 | return [self.collectionView numberOfSections]; 78 | } 79 | 80 | - (CGFloat)wideCellHeight{ 81 | return self.wideCellWidth; 82 | } 83 | 84 | - (CGFloat)cellHeight{ 85 | return self.wideCellHeight/2; 86 | } 87 | 88 | #pragma mark - Layout 89 | -(void)prepareLayout{ 90 | [self calculateValues]; 91 | NSMutableDictionary *tempLayoutDictionary = [NSMutableDictionary dictionary]; 92 | NSMutableDictionary *cellLayoutDictionary = [NSMutableDictionary dictionary]; 93 | NSMutableDictionary *headerLayoutDictionary = [NSMutableDictionary dictionary]; 94 | NSMutableDictionary *footerLayoutDictionary = [NSMutableDictionary dictionary]; 95 | 96 | self.sectionHeaderSizes = [NSMutableDictionary dictionary]; 97 | self.sectionFooterSizes = [NSMutableDictionary dictionary]; 98 | 99 | for (NSInteger section = 0; section < self.numberOfSections; section++) { 100 | NSInteger itemsCount = [self itemsInSection:section]; 101 | 102 | for (NSInteger item = 0; item < itemsCount; item++) { 103 | NSIndexPath *indexPath = [NSIndexPath indexPathForItem:item inSection:section]; 104 | 105 | if (indexPath.item == 0) { 106 | CGSize size = [self estimatedSizeForHeaderInSection:section]; 107 | 108 | if (!CGSizeEqualToSize(size, CGSizeZero)) { 109 | self.sectionHeaderSizes[indexPath] = [NSValue valueWithCGSize:size]; 110 | 111 | UICollectionViewLayoutAttributes *headerAttributes = [UICollectionViewLayoutAttributes 112 | layoutAttributesForSupplementaryViewOfKind:MetroCollectionViewHeader 113 | withIndexPath:indexPath]; 114 | headerAttributes.frame = [self frameForHeaderAtIndexPath:indexPath withSize:size]; 115 | 116 | headerLayoutDictionary[indexPath] = headerAttributes; 117 | } 118 | if (itemsCount == 1) { 119 | CGSize size = [self estimatedSizeForFooterInSection:section]; 120 | 121 | if (!CGSizeEqualToSize(size, CGSizeZero)) { 122 | self.sectionFooterSizes[indexPath] = [NSValue valueWithCGSize:size]; 123 | 124 | UICollectionViewLayoutAttributes *footerAttributes = [UICollectionViewLayoutAttributes layoutAttributesForSupplementaryViewOfKind:MetroCollectionViewFooter 125 | withIndexPath:indexPath]; 126 | footerAttributes.frame = [self frameForFooterAtIndexPath:indexPath withSize:size]; 127 | 128 | footerLayoutDictionary[indexPath] = footerAttributes; 129 | } 130 | } 131 | } else if([self isTheLastItemAtIndexPath:indexPath]) { 132 | CGSize size = [self estimatedSizeForFooterInSection:section]; 133 | 134 | if (!CGSizeEqualToSize(size, CGSizeZero)) { 135 | self.sectionFooterSizes[indexPath] = [NSValue valueWithCGSize:size]; 136 | 137 | UICollectionViewLayoutAttributes *footerAttributes = [UICollectionViewLayoutAttributes layoutAttributesForSupplementaryViewOfKind:MetroCollectionViewFooter withIndexPath:indexPath]; 138 | footerAttributes.frame = [self frameForFooterAtIndexPath:indexPath withSize:size]; 139 | 140 | footerLayoutDictionary[indexPath] = footerAttributes; 141 | } 142 | } 143 | 144 | UICollectionViewLayoutAttributes *layoutAttributes = [UICollectionViewLayoutAttributes layoutAttributesForCellWithIndexPath:indexPath]; 145 | layoutAttributes.frame = [self frameForItemAtIndexPath:indexPath]; 146 | cellLayoutDictionary[indexPath] = layoutAttributes; 147 | } 148 | } 149 | 150 | tempLayoutDictionary[MetroCollectionViewCell] = cellLayoutDictionary; 151 | tempLayoutDictionary[MetroCollectionViewHeader] = headerLayoutDictionary; 152 | tempLayoutDictionary[MetroCollectionViewFooter] = footerLayoutDictionary; 153 | 154 | self.layoutInfoDict = tempLayoutDictionary; 155 | } 156 | 157 | - (BOOL)shouldInvalidateLayoutForBoundsChange:(CGRect)newBounds{ 158 | return YES; 159 | } 160 | 161 | - (NSArray *)layoutAttributesForElementsInRect:(CGRect)rect 162 | { 163 | NSMutableArray *allAttributes = [NSMutableArray arrayWithCapacity:self.layoutInfoDict.count]; 164 | 165 | [self.layoutInfoDict enumerateKeysAndObjectsUsingBlock:^(NSString *elementIdentifier, 166 | NSDictionary *elementsInfo, 167 | BOOL *stop) { 168 | [elementsInfo enumerateKeysAndObjectsUsingBlock:^(NSIndexPath *indexPath, 169 | UICollectionViewLayoutAttributes *attributes, 170 | BOOL *innerStop) { 171 | if (CGRectIntersectsRect(rect, attributes.frame)) { 172 | [allAttributes addObject:attributes]; 173 | } 174 | }]; 175 | }]; 176 | 177 | return allAttributes; 178 | } 179 | 180 | - (UICollectionViewLayoutAttributes *)layoutAttributesForItemAtIndexPath:(NSIndexPath *)indexPath 181 | { 182 | return self.layoutInfoDict[MetroCollectionViewCell][indexPath]; 183 | } 184 | 185 | - (UICollectionViewLayoutAttributes *)layoutAttributesForSupplementaryViewOfKind:(NSString *)kind atIndexPath:(NSIndexPath *)indexPath 186 | { 187 | return self.layoutInfoDict[kind][indexPath]; 188 | } 189 | 190 | - (CGSize)collectionViewContentSize 191 | { 192 | return CGSizeMake(self.collectionView.bounds.size.width, ([self totalContentHeight] + [self sectionSuplementaryElementsHeight:self.numberOfSections])); 193 | } 194 | 195 | #pragma mark - Common Calculations 196 | - (CGFloat)totalContentHeight{ 197 | CGFloat height = 0; 198 | if (self.shouldAutoAlign) { 199 | height = [self totalSectionHeightTillSection:self.numberOfSections]- [self sectionSuplementaryElementsHeight:self.numberOfSections]; 200 | } else { 201 | height = (self.wideCellHeight * [self totalGroupsInCollectionView]); 202 | } 203 | return height; 204 | } 205 | 206 | - (CGFloat)totalSectionHeightTillSection:(NSInteger)section{ 207 | CGFloat height = 0; 208 | if (self.shouldAutoAlign) { 209 | for (int i = 0; i < section; i++) { 210 | height += [self sectionContentHeight:i]; 211 | } 212 | height += [self sectionSuplementaryElementsHeight:section]; 213 | } else { 214 | height = (self.wideCellHeight * [self totalGroupsTillSection:section])+[self sectionSuplementaryElementsHeight:section];; 215 | } 216 | return height; 217 | } 218 | 219 | - (CGFloat)sectionContentHeight:(NSInteger)section{ 220 | NSInteger itemsCount = [self itemsInSection:section]; 221 | 222 | CGFloat sectionHeight = (itemsCount / self.numberOfItems) * self.wideCellHeight; 223 | NSUInteger mod = itemsCount % self.numberOfItems; 224 | if (mod > 0) { 225 | sectionHeight += self.cellHeight; 226 | } 227 | 228 | return sectionHeight; 229 | } 230 | 231 | - (CGFloat)sectionSuplementaryElementsHeight:(NSInteger)sectionValue{ 232 | CGFloat totalHeight = 0.f; 233 | for (NSInteger section = 0; section < sectionValue; section++) { 234 | CGSize sizeHeader = [self estimatedSizeForHeaderInSection:section]; 235 | CGSize sizeFooter = [self estimatedSizeForFooterInSection:section]; 236 | 237 | totalHeight += sizeHeader.height + sizeFooter.height; 238 | } 239 | return totalHeight; 240 | } 241 | 242 | #pragma mark - Groups 243 | - (NSInteger)totalGroupsInCollectionView 244 | { 245 | return [self totalGroupsTillSection:self.numberOfSections]; 246 | } 247 | 248 | - (CGFloat)totalGroupsTillSection:(NSInteger)sectionValue{ 249 | NSInteger totalGroups = 0; 250 | for (NSInteger section = 0; section < sectionValue; section++) { 251 | NSIndexPath *indexPath = [NSIndexPath indexPathForItem:0 inSection:section]; 252 | totalGroups += [self totalGroupsAtIndexPath:indexPath]; 253 | } 254 | return totalGroups; 255 | } 256 | 257 | - (NSInteger)totalGroupsAtIndexPath:(NSIndexPath *)indexPath 258 | { 259 | NSInteger itemsCount = [self itemsInSection:indexPath.section]; 260 | 261 | NSInteger resultValue = itemsCount / self.numberOfItems; 262 | 263 | NSUInteger mod = itemsCount % self.numberOfItems; 264 | if (mod > 0) { 265 | resultValue += 1; 266 | } 267 | 268 | return resultValue; 269 | } 270 | 271 | #pragma mark - Header and Footer 272 | - (CGSize)estimatedSizeForHeaderInSection:(NSInteger)section 273 | { 274 | CGSize size = CGSizeZero; 275 | 276 | if ([self.delegate conformsToProtocol:@protocol(MetroCollectionLayoutDelegate)] && [self.delegate respondsToSelector:@selector(collectionView:layout:estimatedSizeForHeaderInSection:)]) { 277 | size = [self.delegate collectionView:self.collectionView layout:self estimatedSizeForHeaderInSection:section]; 278 | } 279 | 280 | return size; 281 | } 282 | 283 | - (CGFloat)heightForHeaderAtIndexPath:(NSIndexPath *)indexPath 284 | { 285 | CGSize size = [self.sectionHeaderSizes[indexPath] CGSizeValue]; 286 | return size.height; 287 | } 288 | 289 | - (CGSize)estimatedSizeForFooterInSection:(NSInteger)section 290 | { 291 | CGSize size = CGSizeZero; 292 | 293 | if ([self.delegate conformsToProtocol:@protocol(MetroCollectionLayoutDelegate)] && [self.delegate respondsToSelector:@selector(collectionView:layout:estimatedSizeForFooterInSection:)]) { 294 | size = [self.delegate collectionView:self.collectionView layout:self estimatedSizeForFooterInSection:section]; 295 | } 296 | 297 | return size; 298 | } 299 | 300 | - (CGRect)frameForHeaderAtIndexPath:(NSIndexPath *)indexPath withSize:(CGSize)size 301 | { 302 | CGRect frame = CGRectZero; 303 | if (indexPath.section == 0) { 304 | frame.origin.y = 0; 305 | } else { 306 | frame.origin.y = [self getYForFooter:NO atIndexPath:indexPath] - size.height; 307 | } 308 | frame.size = size; 309 | 310 | return frame; 311 | } 312 | 313 | - (CGRect)frameForFooterAtIndexPath:(NSIndexPath *)indexPath withSize:(CGSize)size 314 | { 315 | CGRect frame = CGRectZero; 316 | frame.origin.y = [self getYForFooter:YES atIndexPath:indexPath] + [self getHeightForItemAtIndexPath:indexPath]; 317 | frame.size = size; 318 | 319 | return frame; 320 | } 321 | 322 | - (CGFloat)getHeightForItemAtIndexPath:(NSIndexPath *)indexPath{ 323 | NSInteger itemsCount = [self itemsInSection:indexPath.section]; 324 | NSUInteger mod = itemsCount % self.numberOfItems; 325 | if (mod > 0) { 326 | return self.cellHeight; 327 | }else{ 328 | return 0; 329 | } 330 | } 331 | 332 | #pragma mark - Frame Calculations 333 | - (CGRect)frameForItemAtIndexPath:(NSIndexPath *)indexPath{ 334 | return [self frameForCellAtIndexPath:indexPath]; 335 | } 336 | 337 | - (CGRect)frameForCellAtIndexPath:(NSIndexPath *)indexPath 338 | { 339 | CGRect frame = CGRectZero; 340 | 341 | if ([self isWideCellAtIndexPath:indexPath]) { 342 | self.wideCellDirection = [self getDirectionForGroup:[self currentGroupAtIndexPath:indexPath] inSection:indexPath.section]; 343 | CGFloat xValue; 344 | 345 | if (self.wideCellDirection == MetroCollectionLayoutDirectionLeft) { 346 | xValue = 0; 347 | } else { 348 | xValue = (CGRectGetWidth([self.collectionView bounds]) - self.wideCellWidth); 349 | } 350 | 351 | NSInteger currentGroup = [self currentGroupAtIndexPath:indexPath]; 352 | NSIndexPath *indexPathFirstElementCurrentSection = [NSIndexPath indexPathForRow:0 inSection:indexPath.section]; 353 | CGFloat yValue = currentGroup * self.wideCellHeight + [self heightForHeaderAtIndexPath:indexPathFirstElementCurrentSection]; 354 | yValue += [self totalSectionHeightTillSection:indexPath.section]; 355 | 356 | frame = CGRectMake(xValue, yValue, self.wideCellWidth, self.wideCellHeight); 357 | } else { 358 | frame = CGRectMake([self getXAtIndexPath:indexPath], [self getYForFooter:NO atIndexPath:indexPath], self.cellWidth, self.cellHeight); 359 | } 360 | 361 | return frame; 362 | } 363 | 364 | - (MetroCollectionLayoutDirection)getDirectionForGroup:(NSInteger)group inSection:(NSInteger)section{ 365 | if ([self.delegate conformsToProtocol:@protocol(MetroCollectionLayoutDelegate)] && [self.delegate respondsToSelector:@selector(collectionView:layout:directionForGroup:inSection:)]) { 366 | return [self.delegate collectionView:self.collectionView layout:self directionForGroup:group-1 inSection:section]; 367 | }else{ 368 | if ((group-1) % 2 != 0) { 369 | return MetroCollectionLayoutDirectionLeft; 370 | } else { 371 | return MetroCollectionLayoutDirectionRight; 372 | } 373 | } 374 | } 375 | 376 | - (CGFloat)getXAtIndexPath:(NSIndexPath *)indexPath{ 377 | CGFloat coordinateX = 0; 378 | NSInteger multiplyValue; 379 | NSInteger position = indexPath.row % self.numberOfItems; 380 | if ([self isFlatGroupAtIndexPath:indexPath]) { 381 | multiplyValue = indexPath.row % self.numberOfItems; 382 | } else { 383 | if ([self getDirectionForGroup:[self currentGroupAtIndexPath:indexPath] inSection:indexPath.section] == MetroCollectionLayoutDirectionLeft) { 384 | coordinateX = self.wideCellWidth; 385 | multiplyValue = (position -1) % self.itemsPerSubRow; 386 | } else { 387 | multiplyValue = position % self.itemsPerSubRow; 388 | } 389 | } 390 | 391 | coordinateX = coordinateX + (self.cellWidth * multiplyValue); 392 | return coordinateX; 393 | } 394 | 395 | - (CGFloat)getYForFooter:(BOOL)footer atIndexPath:(NSIndexPath *)indexPath 396 | { 397 | NSInteger currentGroup = [self currentGroupAtIndexPath:indexPath]; 398 | CGFloat yValue = 0.0f; 399 | NSIndexPath *indexPathFirstElementCurrentSection = [NSIndexPath indexPathForRow:0 inSection:indexPath.section]; 400 | 401 | NSInteger multiplyValue; 402 | NSInteger maxElement = self.numberOfItems * (currentGroup+1); 403 | NSInteger position = indexPath.row - (maxElement - self.numberOfItems); 404 | if ([self isFlatGroupAtIndexPath:indexPath]) { 405 | multiplyValue = 0; 406 | } else { 407 | if ([self getDirectionForGroup:currentGroup inSection:indexPath.section] == MetroCollectionLayoutDirectionLeft) { 408 | multiplyValue = (position <= self.itemsPerSubRow)? 0 : 1; 409 | if (footer) multiplyValue++; 410 | } else { 411 | multiplyValue = (position / self.itemsPerSubRow); 412 | } 413 | } 414 | 415 | yValue = (currentGroup * self.wideCellHeight) + (self.cellHeight * multiplyValue) + [self heightForHeaderAtIndexPath:indexPathFirstElementCurrentSection]; 416 | 417 | yValue += [self totalSectionHeightTillSection:indexPath.section]; 418 | 419 | return yValue; 420 | } 421 | 422 | #pragma mark - utils 423 | - (BOOL)isTheLastItemAtIndexPath:(NSIndexPath *)indexPath 424 | { 425 | if((indexPath.row + 1) == [self itemsInSection:indexPath.section]) { 426 | return YES; 427 | } 428 | return NO; 429 | } 430 | 431 | -(NSInteger)itemsInSection:(NSInteger)section{ 432 | return [self.collectionView numberOfItemsInSection:section]; 433 | } 434 | 435 | - (NSInteger)currentGroupAtIndexPath:(NSIndexPath *)indexPath 436 | { 437 | NSInteger item = indexPath.row + 1; 438 | NSInteger resultValue = (item / self.numberOfItems)-1; 439 | NSUInteger mod = item % self.numberOfItems; 440 | if (mod > 0) { 441 | resultValue += 1; 442 | } 443 | return resultValue; 444 | } 445 | 446 | - (BOOL)isWideCellAtIndexPath:(NSIndexPath *)indexPath 447 | { 448 | if (self.shouldAutoAlign) { 449 | if ([self isFlatGroupAtIndexPath:indexPath]) { 450 | return NO; 451 | } else { 452 | return [self isWideCellWithAlignmentAtIndexPath:indexPath]; 453 | } 454 | } else { 455 | return [self isWideCellWithAlignmentAtIndexPath:indexPath]; 456 | } 457 | return NO; 458 | } 459 | 460 | - (BOOL)isWideCellWithAlignmentAtIndexPath:(NSIndexPath *)indexPath{ 461 | if ([self getDirectionForGroup:[self currentGroupAtIndexPath:indexPath] inSection:indexPath.section] == MetroCollectionLayoutDirectionLeft) { 462 | if (indexPath.row % (2 * self.numberOfItems) == 0 || indexPath.row % self.numberOfItems==0) { 463 | return YES; 464 | } 465 | } else { 466 | if ((indexPath.row+1) % (2 * self.numberOfItems) == 0 || (indexPath.row+1) % self.numberOfItems == 0) { 467 | return YES; 468 | } 469 | } 470 | return NO; 471 | } 472 | 473 | - (BOOL)isFlatGroupAtIndexPath:(NSIndexPath *)indexPath{ 474 | if (self.shouldAutoAlign) { 475 | NSInteger currentGroup = [self currentGroupAtIndexPath:indexPath]+1; 476 | NSInteger sectionCount = [self itemsInSection:indexPath.section]; 477 | NSInteger result = sectionCount / self.numberOfItems; 478 | if (result >= currentGroup) { 479 | return NO; 480 | } 481 | NSInteger reminder = sectionCount % self.numberOfItems; 482 | return (reminder > 0 && reminder < self.numberOfItems); 483 | } else { 484 | return NO; 485 | } 486 | } 487 | 488 | @end 489 | -------------------------------------------------------------------------------- /MetroCollectionLayout/MetroCollectionLayout.m: -------------------------------------------------------------------------------- 1 | // 2 | // MetroFlowLayout.m 3 | // FlowLayoutSample 4 | // 5 | // Created by Karthik on 3/19/15. 6 | // Copyright (c) 2015 Karthik. All rights reserved. 7 | // 8 | 9 | #import "MetroCollectionLayout.h" 10 | 11 | static NSString *const MetroCollectionViewCell = @"MetroCollectionViewCell"; 12 | NSString *const MetroCollectionViewHeader = @"MetroCollectionViewHeader"; 13 | NSString *const MetroCollectionViewFooter = @"MetroCollectionViewFooter"; 14 | 15 | #define isIPhone (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone) 16 | 17 | @interface MetroCollectionLayout() 18 | 19 | @property (nonatomic, strong) NSDictionary *layoutInfoDict; 20 | @property (nonatomic, strong) NSMutableDictionary *sectionHeaderSizes; 21 | @property (nonatomic, strong) NSMutableDictionary *sectionFooterSizes; 22 | 23 | @property (nonatomic, assign) CGFloat wideCellWidth; 24 | @property (nonatomic, assign) CGFloat wideCellHeight; 25 | @property (nonatomic, assign) CGFloat cellWidth; 26 | @property (nonatomic, assign) CGFloat cellHeight; 27 | 28 | @property (nonatomic, readonly) NSInteger numberOfSections; 29 | @property (nonatomic, readonly) NSInteger itemsPerSubRow; 30 | 31 | @property (nonatomic, assign) MetroCollectionLayoutDirection wideCellDirection; 32 | @property (nonatomic, assign) BOOL shouldAutoAlign; 33 | @property (nonatomic, assign) NSInteger numberOfItems; 34 | 35 | @end 36 | 37 | @implementation MetroCollectionLayout 38 | 39 | - (instancetype)initWithDelegate:(id)delegate{ 40 | self = [super init]; 41 | if (self) { 42 | _delegate = delegate; 43 | } 44 | return self; 45 | } 46 | 47 | #pragma mark - Init 48 | 49 | - (void)calculateValues{ 50 | if (_delegate && [_delegate respondsToSelector:@selector(numberOfItemsPerGroupForCollectionView:andLayout:)]) { 51 | _numberOfItems = [_delegate numberOfItemsPerGroupForCollectionView:self.collectionView andLayout:self]; 52 | }else{ 53 | _numberOfItems = (isIPhone)? 3: 5; 54 | } 55 | 56 | if (_delegate && [_delegate respondsToSelector:@selector(wideCellWidthForCollectionView:andLayout:)]) { 57 | _wideCellWidth = [_delegate wideCellWidthForCollectionView:self.collectionView andLayout:self]; 58 | }else{ 59 | _wideCellWidth = (CGRectGetWidth(self.collectionView.bounds)/2); 60 | } 61 | if (_delegate && [_delegate respondsToSelector:@selector(shouldAutoAlignCollectionView:)]) { 62 | _shouldAutoAlign = [_delegate shouldAutoAlignCollectionView:self.collectionView]; 63 | }else{ 64 | _shouldAutoAlign = NO; 65 | } 66 | } 67 | 68 | - (CGFloat)cellWidth{ 69 | return (CGRectGetWidth([self.collectionView bounds]) - self.wideCellWidth)/self.itemsPerSubRow; 70 | } 71 | 72 | - (NSInteger)itemsPerSubRow{ 73 | return (self.numberOfItems-1)/2; 74 | } 75 | 76 | - (NSInteger)numberOfSections{ 77 | return [self.collectionView numberOfSections]; 78 | } 79 | 80 | - (CGFloat)wideCellHeight{ 81 | return self.wideCellWidth; 82 | } 83 | 84 | - (CGFloat)cellHeight{ 85 | return self.wideCellHeight/2; 86 | } 87 | 88 | #pragma mark - Layout 89 | -(void)prepareLayout{ 90 | [self calculateValues]; 91 | NSMutableDictionary *tempLayoutDictionary = [NSMutableDictionary dictionary]; 92 | NSMutableDictionary *cellLayoutDictionary = [NSMutableDictionary dictionary]; 93 | NSMutableDictionary *headerLayoutDictionary = [NSMutableDictionary dictionary]; 94 | NSMutableDictionary *footerLayoutDictionary = [NSMutableDictionary dictionary]; 95 | 96 | self.sectionHeaderSizes = [NSMutableDictionary dictionary]; 97 | self.sectionFooterSizes = [NSMutableDictionary dictionary]; 98 | 99 | for (NSInteger section = 0; section < self.numberOfSections; section++) { 100 | NSInteger itemsCount = [self itemsInSection:section]; 101 | 102 | for (NSInteger item = 0; item < itemsCount; item++) { 103 | NSIndexPath *indexPath = [NSIndexPath indexPathForItem:item inSection:section]; 104 | 105 | if (indexPath.item == 0) { 106 | CGSize size = [self estimatedSizeForHeaderInSection:section]; 107 | 108 | if (!CGSizeEqualToSize(size, CGSizeZero)) { 109 | self.sectionHeaderSizes[indexPath] = [NSValue valueWithCGSize:size]; 110 | 111 | UICollectionViewLayoutAttributes *headerAttributes = [UICollectionViewLayoutAttributes 112 | layoutAttributesForSupplementaryViewOfKind:MetroCollectionViewHeader 113 | withIndexPath:indexPath]; 114 | headerAttributes.frame = [self frameForHeaderAtIndexPath:indexPath withSize:size]; 115 | 116 | headerLayoutDictionary[indexPath] = headerAttributes; 117 | } 118 | if (itemsCount == 1) { 119 | CGSize size = [self estimatedSizeForFooterInSection:section]; 120 | 121 | if (!CGSizeEqualToSize(size, CGSizeZero)) { 122 | self.sectionFooterSizes[indexPath] = [NSValue valueWithCGSize:size]; 123 | 124 | UICollectionViewLayoutAttributes *footerAttributes = [UICollectionViewLayoutAttributes 125 | layoutAttributesForSupplementaryViewOfKind:MetroCollectionViewFooter 126 | withIndexPath:indexPath]; 127 | footerAttributes.frame = [self frameForFooterAtIndexPath:indexPath withSize:size]; 128 | 129 | footerLayoutDictionary[indexPath] = footerAttributes; 130 | } 131 | } 132 | } else if([self isTheLastItemAtIndexPath:indexPath]) { 133 | CGSize size = [self estimatedSizeForFooterInSection:section]; 134 | 135 | if (!CGSizeEqualToSize(size, CGSizeZero)) { 136 | self.sectionFooterSizes[indexPath] = [NSValue valueWithCGSize:size]; 137 | 138 | UICollectionViewLayoutAttributes *footerAttributes = [UICollectionViewLayoutAttributes 139 | layoutAttributesForSupplementaryViewOfKind:MetroCollectionViewFooter 140 | withIndexPath:indexPath]; 141 | footerAttributes.frame = [self frameForFooterAtIndexPath:indexPath withSize:size]; 142 | 143 | footerLayoutDictionary[indexPath] = footerAttributes; 144 | } 145 | } 146 | 147 | UICollectionViewLayoutAttributes *layoutAttributes = [UICollectionViewLayoutAttributes layoutAttributesForCellWithIndexPath:indexPath]; 148 | layoutAttributes.frame = [self frameForItemAtIndexPath:indexPath]; 149 | cellLayoutDictionary[indexPath] = layoutAttributes; 150 | } 151 | } 152 | 153 | tempLayoutDictionary[MetroCollectionViewCell] = cellLayoutDictionary; 154 | tempLayoutDictionary[MetroCollectionViewHeader] = headerLayoutDictionary; 155 | tempLayoutDictionary[MetroCollectionViewFooter] = footerLayoutDictionary; 156 | 157 | self.layoutInfoDict = tempLayoutDictionary; 158 | } 159 | 160 | - (BOOL)shouldInvalidateLayoutForBoundsChange:(CGRect)newBounds{ 161 | return YES; 162 | } 163 | 164 | - (NSArray *)layoutAttributesForElementsInRect:(CGRect)rect 165 | { 166 | NSMutableArray *allAttributes = [NSMutableArray arrayWithCapacity:self.layoutInfoDict.count]; 167 | 168 | [self.layoutInfoDict enumerateKeysAndObjectsUsingBlock:^(NSString *elementIdentifier, 169 | NSDictionary *elementsInfo, 170 | BOOL *stop) { 171 | [elementsInfo enumerateKeysAndObjectsUsingBlock:^(NSIndexPath *indexPath, 172 | UICollectionViewLayoutAttributes *attributes, 173 | BOOL *innerStop) { 174 | if (CGRectIntersectsRect(rect, attributes.frame)) { 175 | [allAttributes addObject:attributes]; 176 | } 177 | }]; 178 | }]; 179 | 180 | return allAttributes; 181 | } 182 | 183 | - (UICollectionViewLayoutAttributes *)layoutAttributesForItemAtIndexPath:(NSIndexPath *)indexPath 184 | { 185 | return self.layoutInfoDict[MetroCollectionViewCell][indexPath]; 186 | } 187 | 188 | - (UICollectionViewLayoutAttributes *)layoutAttributesForSupplementaryViewOfKind:(NSString *)kind atIndexPath:(NSIndexPath *)indexPath 189 | { 190 | return self.layoutInfoDict[kind][indexPath]; 191 | } 192 | 193 | - (CGSize)collectionViewContentSize 194 | { 195 | return CGSizeMake(self.collectionView.bounds.size.width, ([self totalContentHeight] + [self sectionSuplementaryElementsHeight:self.numberOfSections])); 196 | } 197 | 198 | #pragma mark - Common Calculations 199 | - (CGFloat)totalContentHeight{ 200 | CGFloat height = 0; 201 | if (self.shouldAutoAlign) { 202 | height = [self totalSectionHeightTillSection:self.numberOfSections]- [self sectionSuplementaryElementsHeight:self.numberOfSections]; 203 | } else { 204 | height = (self.wideCellHeight * [self totalGroupsInCollectionView]); 205 | } 206 | return height; 207 | } 208 | 209 | - (CGFloat)totalSectionHeightTillSection:(NSInteger)section{ 210 | CGFloat height = 0; 211 | if (self.shouldAutoAlign) { 212 | for (int i = 0; i < section; i++) { 213 | height += [self sectionContentHeight:i]; 214 | } 215 | height += [self sectionSuplementaryElementsHeight:section]; 216 | } else { 217 | height = (self.wideCellHeight * [self totalGroupsTillSection:section])+[self sectionSuplementaryElementsHeight:section];; 218 | } 219 | return height; 220 | } 221 | 222 | - (CGFloat)sectionContentHeight:(NSInteger)section{ 223 | NSInteger itemsCount = [self itemsInSection:section]; 224 | 225 | CGFloat sectionHeight = (itemsCount / self.numberOfItems) * self.wideCellHeight; 226 | NSUInteger mod = itemsCount % self.numberOfItems; 227 | if (mod > 0) { 228 | sectionHeight += self.cellHeight; 229 | } 230 | 231 | return sectionHeight; 232 | } 233 | 234 | - (CGFloat)sectionSuplementaryElementsHeight:(NSInteger)sectionValue{ 235 | CGFloat totalHeight = 0.f; 236 | for (NSInteger section = 0; section < sectionValue; section++) { 237 | CGSize sizeHeader = [self estimatedSizeForHeaderInSection:section]; 238 | CGSize sizeFooter = [self estimatedSizeForFooterInSection:section]; 239 | 240 | totalHeight += sizeHeader.height + sizeFooter.height; 241 | } 242 | return totalHeight; 243 | } 244 | 245 | #pragma mark - Groups 246 | - (NSInteger)totalGroupsInCollectionView 247 | { 248 | return [self totalGroupsTillSection:self.numberOfSections]; 249 | } 250 | 251 | - (CGFloat)totalGroupsTillSection:(NSInteger)sectionValue{ 252 | NSInteger totalGroups = 0; 253 | for (NSInteger section = 0; section < sectionValue; section++) { 254 | NSIndexPath *indexPath = [NSIndexPath indexPathForItem:0 inSection:section]; 255 | totalGroups += [self totalGroupsAtIndexPath:indexPath]; 256 | } 257 | return totalGroups; 258 | } 259 | 260 | - (NSInteger)totalGroupsAtIndexPath:(NSIndexPath *)indexPath 261 | { 262 | NSInteger itemsCount = [self itemsInSection:indexPath.section]; 263 | 264 | NSInteger resultValue = itemsCount / self.numberOfItems; 265 | 266 | NSUInteger mod = itemsCount % self.numberOfItems; 267 | if (mod > 0) { 268 | resultValue += 1; 269 | } 270 | 271 | return resultValue; 272 | } 273 | 274 | #pragma mark - Header and Footer 275 | - (CGSize)estimatedSizeForHeaderInSection:(NSInteger)section 276 | { 277 | CGSize size = CGSizeZero; 278 | 279 | if ([self.delegate conformsToProtocol:@protocol(MetroCollectionLayoutDelegate)] && [self.delegate respondsToSelector:@selector(collectionView:layout:estimatedSizeForHeaderInSection:)]) { 280 | size = [self.delegate collectionView:self.collectionView layout:self estimatedSizeForHeaderInSection:section]; 281 | } 282 | 283 | return size; 284 | } 285 | 286 | - (CGFloat)heightForHeaderAtIndexPath:(NSIndexPath *)indexPath 287 | { 288 | CGSize size = [self.sectionHeaderSizes[indexPath] CGSizeValue]; 289 | return size.height; 290 | } 291 | 292 | - (CGSize)estimatedSizeForFooterInSection:(NSInteger)section 293 | { 294 | CGSize size = CGSizeZero; 295 | 296 | if ([self.delegate conformsToProtocol:@protocol(MetroCollectionLayoutDelegate)] && [self.delegate respondsToSelector:@selector(collectionView:layout:estimatedSizeForFooterInSection:)]) { 297 | size = [self.delegate collectionView:self.collectionView layout:self estimatedSizeForFooterInSection:section]; 298 | } 299 | 300 | return size; 301 | } 302 | 303 | - (CGRect)frameForHeaderAtIndexPath:(NSIndexPath *)indexPath withSize:(CGSize)size 304 | { 305 | CGRect frame = CGRectZero; 306 | if (indexPath.section == 0) { 307 | frame.origin.y = 0; 308 | } else { 309 | frame.origin.y = [self getYAtIndexPath:indexPath] - size.height; 310 | } 311 | frame.size = size; 312 | 313 | return frame; 314 | } 315 | 316 | - (CGRect)frameForFooterAtIndexPath:(NSIndexPath *)indexPath withSize:(CGSize)size 317 | { 318 | CGRect frame = CGRectZero; 319 | frame.origin.y = [self getYAtIndexPath:indexPath] + [self getHeightForItemAtIndexPath:indexPath]; 320 | frame.size = size; 321 | 322 | return frame; 323 | } 324 | 325 | - (CGFloat)getHeightForItemAtIndexPath:(NSIndexPath *)indexPath{ 326 | NSInteger itemsCount = [self itemsInSection:indexPath.section]; 327 | NSUInteger mod = itemsCount % self.numberOfItems; 328 | if (mod > 0) { 329 | return self.cellHeight; 330 | }else{ 331 | return self.wideCellHeight; 332 | } 333 | } 334 | 335 | #pragma mark - Frame Calculations 336 | - (CGRect)frameForItemAtIndexPath:(NSIndexPath *)indexPath{ 337 | return [self frameForCellAtIndexPath:indexPath]; 338 | } 339 | 340 | - (CGRect)frameForCellAtIndexPath:(NSIndexPath *)indexPath 341 | { 342 | CGRect frame = CGRectZero; 343 | 344 | if ([self isWideElementAtIndexPath:indexPath]) { 345 | self.wideCellDirection = [self getDirectionForGroup:[self currentGroupAtIndexPath:indexPath] inSection:indexPath.section]; 346 | CGFloat xValue; 347 | 348 | if (self.wideCellDirection == MetroCollectionLayoutDirectionLeft) { 349 | xValue = 0; 350 | } else { 351 | xValue = (CGRectGetWidth([self.collectionView bounds]) - self.wideCellWidth); 352 | } 353 | 354 | NSInteger currentGroup = [self currentGroupAtIndexPath:indexPath]; 355 | NSIndexPath *indexPathFirstElementCurrentSection = [NSIndexPath indexPathForRow:0 inSection:indexPath.section]; 356 | CGFloat yValue = (currentGroup - 1) * self.wideCellHeight + [self heightForHeaderAtIndexPath:indexPathFirstElementCurrentSection]; 357 | yValue += [self totalSectionHeightTillSection:indexPath.section]; 358 | 359 | frame = CGRectMake(xValue, yValue, self.wideCellWidth, self.wideCellHeight); 360 | } else { 361 | frame = CGRectMake([self getXAtIndexPath:indexPath], [self getYAtIndexPath:indexPath], self.cellWidth, self.cellHeight); 362 | } 363 | 364 | return frame; 365 | } 366 | 367 | - (MetroCollectionLayoutDirection)getDirectionForGroup:(NSInteger)group inSection:(NSInteger)section{ 368 | if ([self.delegate conformsToProtocol:@protocol(MetroCollectionLayoutDelegate)] && [self.delegate respondsToSelector:@selector(collectionView:layout:directionForGroup:inSection:)]) { 369 | return [self.delegate collectionView:self.collectionView layout:self directionForGroup:group-1 inSection:section]; 370 | }else{ 371 | if ((group-1) % 2 == 0) { 372 | return MetroCollectionLayoutDirectionLeft; 373 | } else { 374 | return MetroCollectionLayoutDirectionRight; 375 | } 376 | } 377 | } 378 | 379 | - (CGFloat)getXAtIndexPath:(NSIndexPath *)indexPath{ 380 | CGFloat coordinateX = 0; 381 | NSInteger multiplyValue; 382 | NSInteger position = indexPath.row % self.numberOfItems; 383 | if ([self isFlatGroupAtIndexPath:indexPath]) { 384 | multiplyValue = indexPath.row % self.numberOfItems; 385 | } else { 386 | if ([self getDirectionForGroup:[self currentGroupAtIndexPath:indexPath] inSection:indexPath.section] == MetroCollectionLayoutDirectionLeft) { 387 | coordinateX = self.wideCellWidth; 388 | multiplyValue = (position -1) % self.itemsPerSubRow; 389 | } else { 390 | multiplyValue = position % self.itemsPerSubRow; 391 | } 392 | } 393 | 394 | coordinateX = coordinateX + (self.cellWidth * multiplyValue); 395 | return coordinateX; 396 | } 397 | 398 | - (CGFloat)getYAtIndexPath:(NSIndexPath *)indexPath 399 | { 400 | NSInteger currentGroup = [self currentGroupAtIndexPath:indexPath]; 401 | CGFloat yValue = 0.0f; 402 | NSIndexPath *indexPathFirstElementCurrentSection = [NSIndexPath indexPathForRow:0 inSection:indexPath.section]; 403 | 404 | NSInteger multiplyValue; 405 | NSInteger maxElement = self.numberOfItems * currentGroup; 406 | NSInteger position = indexPath.row - (maxElement - self.numberOfItems); 407 | if ([self isFlatGroupAtIndexPath:indexPath]) { 408 | multiplyValue = 0; 409 | } else { 410 | if ([self getDirectionForGroup:currentGroup inSection:indexPath.section] == MetroCollectionLayoutDirectionLeft) { 411 | multiplyValue = (position <= self.itemsPerSubRow)? 0 : 1; 412 | } else { 413 | multiplyValue = (position / self.itemsPerSubRow); 414 | } 415 | } 416 | 417 | yValue = ((currentGroup - 1) * self.wideCellHeight) + (self.cellHeight * multiplyValue) + [self heightForHeaderAtIndexPath:indexPathFirstElementCurrentSection]; 418 | 419 | yValue += [self totalSectionHeightTillSection:indexPath.section]; 420 | 421 | return yValue; 422 | } 423 | 424 | #pragma mark - utils 425 | - (BOOL)isTheLastItemAtIndexPath:(NSIndexPath *)indexPath 426 | { 427 | if((indexPath.row + 1) == [self itemsInSection:indexPath.section]) { 428 | return YES; 429 | } 430 | return NO; 431 | } 432 | 433 | -(NSInteger)itemsInSection:(NSInteger)section{ 434 | return [self.collectionView numberOfItemsInSection:section]; 435 | } 436 | 437 | - (NSInteger)currentGroupAtIndexPath:(NSIndexPath *)indexPath 438 | { 439 | NSInteger item = indexPath.row + 1; 440 | NSInteger resultValue = item / self.numberOfItems; 441 | NSUInteger mod = item % self.numberOfItems; 442 | if (mod > 0) { 443 | resultValue += 1; 444 | } 445 | return resultValue; 446 | } 447 | 448 | - (BOOL)isWideElementAtIndexPath:(NSIndexPath *)indexPath 449 | { 450 | if (self.shouldAutoAlign) { 451 | if ([self isFlatGroupAtIndexPath:indexPath]) { 452 | return NO; 453 | } else { 454 | return [self isWideElementWithAlignmentAtIndexPath:indexPath]; 455 | } 456 | } else { 457 | return [self isWideElementWithAlignmentAtIndexPath:indexPath]; 458 | } 459 | return NO; 460 | } 461 | 462 | - (BOOL)isWideElementWithAlignmentAtIndexPath:(NSIndexPath *)indexPath{ 463 | if ([self getDirectionForGroup:[self currentGroupAtIndexPath:indexPath] inSection:indexPath.section] == MetroCollectionLayoutDirectionLeft) { 464 | if (indexPath.row % (2 * self.numberOfItems) == 0 || indexPath.row % self.numberOfItems==0) { 465 | return YES; 466 | } 467 | } else { 468 | if ((indexPath.row+1) % (2 * self.numberOfItems) == 0 || (indexPath.row+1) % self.numberOfItems == 0) { 469 | return YES; 470 | } 471 | } 472 | return NO; 473 | } 474 | 475 | - (BOOL)isFlatGroupAtIndexPath:(NSIndexPath *)indexPath{ 476 | if (self.shouldAutoAlign) { 477 | NSInteger currentGroup = [self currentGroupAtIndexPath:indexPath]; 478 | NSInteger sectionCount = [self itemsInSection:indexPath.section]; 479 | NSInteger result = sectionCount / self.numberOfItems; 480 | if (result >= currentGroup) { 481 | return NO; 482 | } 483 | NSInteger reminder = sectionCount % self.numberOfItems; 484 | return (reminder > 0 && reminder < self.numberOfItems); 485 | } else { 486 | return NO; 487 | } 488 | } 489 | 490 | @end 491 | -------------------------------------------------------------------------------- /MetroCollectionLayoutSample/MetroCollectionLayoutSample.xcodeproj/project.pbxproj: -------------------------------------------------------------------------------- 1 | // !$*UTF8*$! 2 | { 3 | archiveVersion = 1; 4 | classes = { 5 | }; 6 | objectVersion = 46; 7 | objects = { 8 | 9 | /* Begin PBXBuildFile section */ 10 | 255A29761AE02CF6002B62BA /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = 255A29751AE02CF6002B62BA /* main.m */; }; 11 | 255A29791AE02CF6002B62BA /* AppDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = 255A29781AE02CF6002B62BA /* AppDelegate.m */; }; 12 | 255A297C1AE02CF6002B62BA /* ViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 255A297B1AE02CF6002B62BA /* ViewController.m */; }; 13 | 255A297F1AE02CF6002B62BA /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 255A297D1AE02CF6002B62BA /* Main.storyboard */; }; 14 | 255A29811AE02CF6002B62BA /* Images.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 255A29801AE02CF6002B62BA /* Images.xcassets */; }; 15 | 255A29841AE02CF6002B62BA /* LaunchScreen.xib in Resources */ = {isa = PBXBuildFile; fileRef = 255A29821AE02CF6002B62BA /* LaunchScreen.xib */; }; 16 | 255A29901AE02CF6002B62BA /* MetroCollectionLayoutSampleTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 255A298F1AE02CF6002B62BA /* MetroCollectionLayoutSampleTests.m */; }; 17 | 255A299C1AE02DB0002B62BA /* MetroCollectionLayout.m in Sources */ = {isa = PBXBuildFile; fileRef = 255A299B1AE02DB0002B62BA /* MetroCollectionLayout.m */; }; 18 | 255A29A01AE02DF5002B62BA /* MetroCollectionViewCell.m in Sources */ = {isa = PBXBuildFile; fileRef = 255A299F1AE02DF5002B62BA /* MetroCollectionViewCell.m */; }; 19 | /* End PBXBuildFile section */ 20 | 21 | /* Begin PBXContainerItemProxy section */ 22 | 255A298A1AE02CF6002B62BA /* PBXContainerItemProxy */ = { 23 | isa = PBXContainerItemProxy; 24 | containerPortal = 255A29681AE02CF6002B62BA /* Project object */; 25 | proxyType = 1; 26 | remoteGlobalIDString = 255A296F1AE02CF6002B62BA; 27 | remoteInfo = MetroCollectionLayoutSample; 28 | }; 29 | /* End PBXContainerItemProxy section */ 30 | 31 | /* Begin PBXFileReference section */ 32 | 255A29701AE02CF6002B62BA /* MetroCollectionLayoutSample.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = MetroCollectionLayoutSample.app; sourceTree = BUILT_PRODUCTS_DIR; }; 33 | 255A29741AE02CF6002B62BA /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 34 | 255A29751AE02CF6002B62BA /* main.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = main.m; sourceTree = ""; }; 35 | 255A29771AE02CF6002B62BA /* AppDelegate.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = AppDelegate.h; sourceTree = ""; }; 36 | 255A29781AE02CF6002B62BA /* AppDelegate.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = AppDelegate.m; sourceTree = ""; }; 37 | 255A297A1AE02CF6002B62BA /* ViewController.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = ViewController.h; sourceTree = ""; }; 38 | 255A297B1AE02CF6002B62BA /* ViewController.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = ViewController.m; sourceTree = ""; }; 39 | 255A297E1AE02CF6002B62BA /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/Main.storyboard; sourceTree = ""; }; 40 | 255A29801AE02CF6002B62BA /* Images.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Images.xcassets; sourceTree = ""; }; 41 | 255A29831AE02CF6002B62BA /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.xib; name = Base; path = Base.lproj/LaunchScreen.xib; sourceTree = ""; }; 42 | 255A29891AE02CF6002B62BA /* MetroCollectionLayoutSampleTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = MetroCollectionLayoutSampleTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; }; 43 | 255A298E1AE02CF6002B62BA /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 44 | 255A298F1AE02CF6002B62BA /* MetroCollectionLayoutSampleTests.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = MetroCollectionLayoutSampleTests.m; sourceTree = ""; }; 45 | 255A299A1AE02DB0002B62BA /* MetroCollectionLayout.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MetroCollectionLayout.h; sourceTree = ""; }; 46 | 255A299B1AE02DB0002B62BA /* MetroCollectionLayout.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MetroCollectionLayout.m; sourceTree = ""; }; 47 | 255A299E1AE02DF5002B62BA /* MetroCollectionViewCell.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = MetroCollectionViewCell.h; path = Views/MetroCollectionViewCell.h; sourceTree = ""; }; 48 | 255A299F1AE02DF5002B62BA /* MetroCollectionViewCell.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = MetroCollectionViewCell.m; path = Views/MetroCollectionViewCell.m; sourceTree = ""; }; 49 | /* End PBXFileReference section */ 50 | 51 | /* Begin PBXFrameworksBuildPhase section */ 52 | 255A296D1AE02CF6002B62BA /* Frameworks */ = { 53 | isa = PBXFrameworksBuildPhase; 54 | buildActionMask = 2147483647; 55 | files = ( 56 | ); 57 | runOnlyForDeploymentPostprocessing = 0; 58 | }; 59 | 255A29861AE02CF6002B62BA /* Frameworks */ = { 60 | isa = PBXFrameworksBuildPhase; 61 | buildActionMask = 2147483647; 62 | files = ( 63 | ); 64 | runOnlyForDeploymentPostprocessing = 0; 65 | }; 66 | /* End PBXFrameworksBuildPhase section */ 67 | 68 | /* Begin PBXGroup section */ 69 | 255A29671AE02CF6002B62BA = { 70 | isa = PBXGroup; 71 | children = ( 72 | 255A29991AE02DB0002B62BA /* MetroCollectionLayout */, 73 | 255A29721AE02CF6002B62BA /* MetroCollectionLayoutSample */, 74 | 255A298C1AE02CF6002B62BA /* MetroCollectionLayoutSampleTests */, 75 | 255A29711AE02CF6002B62BA /* Products */, 76 | ); 77 | sourceTree = ""; 78 | }; 79 | 255A29711AE02CF6002B62BA /* Products */ = { 80 | isa = PBXGroup; 81 | children = ( 82 | 255A29701AE02CF6002B62BA /* MetroCollectionLayoutSample.app */, 83 | 255A29891AE02CF6002B62BA /* MetroCollectionLayoutSampleTests.xctest */, 84 | ); 85 | name = Products; 86 | sourceTree = ""; 87 | }; 88 | 255A29721AE02CF6002B62BA /* MetroCollectionLayoutSample */ = { 89 | isa = PBXGroup; 90 | children = ( 91 | 255A299D1AE02DBF002B62BA /* Cells */, 92 | 255A29771AE02CF6002B62BA /* AppDelegate.h */, 93 | 255A29781AE02CF6002B62BA /* AppDelegate.m */, 94 | 255A297A1AE02CF6002B62BA /* ViewController.h */, 95 | 255A297B1AE02CF6002B62BA /* ViewController.m */, 96 | 255A297D1AE02CF6002B62BA /* Main.storyboard */, 97 | 255A29801AE02CF6002B62BA /* Images.xcassets */, 98 | 255A29821AE02CF6002B62BA /* LaunchScreen.xib */, 99 | 255A29731AE02CF6002B62BA /* Supporting Files */, 100 | ); 101 | path = MetroCollectionLayoutSample; 102 | sourceTree = ""; 103 | }; 104 | 255A29731AE02CF6002B62BA /* Supporting Files */ = { 105 | isa = PBXGroup; 106 | children = ( 107 | 255A29741AE02CF6002B62BA /* Info.plist */, 108 | 255A29751AE02CF6002B62BA /* main.m */, 109 | ); 110 | name = "Supporting Files"; 111 | sourceTree = ""; 112 | }; 113 | 255A298C1AE02CF6002B62BA /* MetroCollectionLayoutSampleTests */ = { 114 | isa = PBXGroup; 115 | children = ( 116 | 255A298F1AE02CF6002B62BA /* MetroCollectionLayoutSampleTests.m */, 117 | 255A298D1AE02CF6002B62BA /* Supporting Files */, 118 | ); 119 | path = MetroCollectionLayoutSampleTests; 120 | sourceTree = ""; 121 | }; 122 | 255A298D1AE02CF6002B62BA /* Supporting Files */ = { 123 | isa = PBXGroup; 124 | children = ( 125 | 255A298E1AE02CF6002B62BA /* Info.plist */, 126 | ); 127 | name = "Supporting Files"; 128 | sourceTree = ""; 129 | }; 130 | 255A29991AE02DB0002B62BA /* MetroCollectionLayout */ = { 131 | isa = PBXGroup; 132 | children = ( 133 | 255A299A1AE02DB0002B62BA /* MetroCollectionLayout.h */, 134 | 255A299B1AE02DB0002B62BA /* MetroCollectionLayout.m */, 135 | ); 136 | path = MetroCollectionLayout; 137 | sourceTree = ""; 138 | }; 139 | 255A299D1AE02DBF002B62BA /* Cells */ = { 140 | isa = PBXGroup; 141 | children = ( 142 | 255A299E1AE02DF5002B62BA /* MetroCollectionViewCell.h */, 143 | 255A299F1AE02DF5002B62BA /* MetroCollectionViewCell.m */, 144 | ); 145 | name = Cells; 146 | sourceTree = ""; 147 | }; 148 | /* End PBXGroup section */ 149 | 150 | /* Begin PBXNativeTarget section */ 151 | 255A296F1AE02CF6002B62BA /* MetroCollectionLayoutSample */ = { 152 | isa = PBXNativeTarget; 153 | buildConfigurationList = 255A29931AE02CF6002B62BA /* Build configuration list for PBXNativeTarget "MetroCollectionLayoutSample" */; 154 | buildPhases = ( 155 | 255A296C1AE02CF6002B62BA /* Sources */, 156 | 255A296D1AE02CF6002B62BA /* Frameworks */, 157 | 255A296E1AE02CF6002B62BA /* Resources */, 158 | ); 159 | buildRules = ( 160 | ); 161 | dependencies = ( 162 | ); 163 | name = MetroCollectionLayoutSample; 164 | productName = MetroCollectionLayoutSample; 165 | productReference = 255A29701AE02CF6002B62BA /* MetroCollectionLayoutSample.app */; 166 | productType = "com.apple.product-type.application"; 167 | }; 168 | 255A29881AE02CF6002B62BA /* MetroCollectionLayoutSampleTests */ = { 169 | isa = PBXNativeTarget; 170 | buildConfigurationList = 255A29961AE02CF6002B62BA /* Build configuration list for PBXNativeTarget "MetroCollectionLayoutSampleTests" */; 171 | buildPhases = ( 172 | 255A29851AE02CF6002B62BA /* Sources */, 173 | 255A29861AE02CF6002B62BA /* Frameworks */, 174 | 255A29871AE02CF6002B62BA /* Resources */, 175 | ); 176 | buildRules = ( 177 | ); 178 | dependencies = ( 179 | 255A298B1AE02CF6002B62BA /* PBXTargetDependency */, 180 | ); 181 | name = MetroCollectionLayoutSampleTests; 182 | productName = MetroCollectionLayoutSampleTests; 183 | productReference = 255A29891AE02CF6002B62BA /* MetroCollectionLayoutSampleTests.xctest */; 184 | productType = "com.apple.product-type.bundle.unit-test"; 185 | }; 186 | /* End PBXNativeTarget section */ 187 | 188 | /* Begin PBXProject section */ 189 | 255A29681AE02CF6002B62BA /* Project object */ = { 190 | isa = PBXProject; 191 | attributes = { 192 | LastUpgradeCheck = 0630; 193 | ORGANIZATIONNAME = "Karti Codes"; 194 | TargetAttributes = { 195 | 255A296F1AE02CF6002B62BA = { 196 | CreatedOnToolsVersion = 6.3; 197 | }; 198 | 255A29881AE02CF6002B62BA = { 199 | CreatedOnToolsVersion = 6.3; 200 | TestTargetID = 255A296F1AE02CF6002B62BA; 201 | }; 202 | }; 203 | }; 204 | buildConfigurationList = 255A296B1AE02CF6002B62BA /* Build configuration list for PBXProject "MetroCollectionLayoutSample" */; 205 | compatibilityVersion = "Xcode 3.2"; 206 | developmentRegion = English; 207 | hasScannedForEncodings = 0; 208 | knownRegions = ( 209 | en, 210 | Base, 211 | ); 212 | mainGroup = 255A29671AE02CF6002B62BA; 213 | productRefGroup = 255A29711AE02CF6002B62BA /* Products */; 214 | projectDirPath = ""; 215 | projectRoot = ""; 216 | targets = ( 217 | 255A296F1AE02CF6002B62BA /* MetroCollectionLayoutSample */, 218 | 255A29881AE02CF6002B62BA /* MetroCollectionLayoutSampleTests */, 219 | ); 220 | }; 221 | /* End PBXProject section */ 222 | 223 | /* Begin PBXResourcesBuildPhase section */ 224 | 255A296E1AE02CF6002B62BA /* Resources */ = { 225 | isa = PBXResourcesBuildPhase; 226 | buildActionMask = 2147483647; 227 | files = ( 228 | 255A297F1AE02CF6002B62BA /* Main.storyboard in Resources */, 229 | 255A29841AE02CF6002B62BA /* LaunchScreen.xib in Resources */, 230 | 255A29811AE02CF6002B62BA /* Images.xcassets in Resources */, 231 | ); 232 | runOnlyForDeploymentPostprocessing = 0; 233 | }; 234 | 255A29871AE02CF6002B62BA /* Resources */ = { 235 | isa = PBXResourcesBuildPhase; 236 | buildActionMask = 2147483647; 237 | files = ( 238 | ); 239 | runOnlyForDeploymentPostprocessing = 0; 240 | }; 241 | /* End PBXResourcesBuildPhase section */ 242 | 243 | /* Begin PBXSourcesBuildPhase section */ 244 | 255A296C1AE02CF6002B62BA /* Sources */ = { 245 | isa = PBXSourcesBuildPhase; 246 | buildActionMask = 2147483647; 247 | files = ( 248 | 255A29A01AE02DF5002B62BA /* MetroCollectionViewCell.m in Sources */, 249 | 255A297C1AE02CF6002B62BA /* ViewController.m in Sources */, 250 | 255A29791AE02CF6002B62BA /* AppDelegate.m in Sources */, 251 | 255A29761AE02CF6002B62BA /* main.m in Sources */, 252 | 255A299C1AE02DB0002B62BA /* MetroCollectionLayout.m in Sources */, 253 | ); 254 | runOnlyForDeploymentPostprocessing = 0; 255 | }; 256 | 255A29851AE02CF6002B62BA /* Sources */ = { 257 | isa = PBXSourcesBuildPhase; 258 | buildActionMask = 2147483647; 259 | files = ( 260 | 255A29901AE02CF6002B62BA /* MetroCollectionLayoutSampleTests.m in Sources */, 261 | ); 262 | runOnlyForDeploymentPostprocessing = 0; 263 | }; 264 | /* End PBXSourcesBuildPhase section */ 265 | 266 | /* Begin PBXTargetDependency section */ 267 | 255A298B1AE02CF6002B62BA /* PBXTargetDependency */ = { 268 | isa = PBXTargetDependency; 269 | target = 255A296F1AE02CF6002B62BA /* MetroCollectionLayoutSample */; 270 | targetProxy = 255A298A1AE02CF6002B62BA /* PBXContainerItemProxy */; 271 | }; 272 | /* End PBXTargetDependency section */ 273 | 274 | /* Begin PBXVariantGroup section */ 275 | 255A297D1AE02CF6002B62BA /* Main.storyboard */ = { 276 | isa = PBXVariantGroup; 277 | children = ( 278 | 255A297E1AE02CF6002B62BA /* Base */, 279 | ); 280 | name = Main.storyboard; 281 | sourceTree = ""; 282 | }; 283 | 255A29821AE02CF6002B62BA /* LaunchScreen.xib */ = { 284 | isa = PBXVariantGroup; 285 | children = ( 286 | 255A29831AE02CF6002B62BA /* Base */, 287 | ); 288 | name = LaunchScreen.xib; 289 | sourceTree = ""; 290 | }; 291 | /* End PBXVariantGroup section */ 292 | 293 | /* Begin XCBuildConfiguration section */ 294 | 255A29911AE02CF6002B62BA /* Debug */ = { 295 | isa = XCBuildConfiguration; 296 | buildSettings = { 297 | ALWAYS_SEARCH_USER_PATHS = NO; 298 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; 299 | CLANG_CXX_LIBRARY = "libc++"; 300 | CLANG_ENABLE_MODULES = YES; 301 | CLANG_ENABLE_OBJC_ARC = YES; 302 | CLANG_WARN_BOOL_CONVERSION = YES; 303 | CLANG_WARN_CONSTANT_CONVERSION = YES; 304 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 305 | CLANG_WARN_EMPTY_BODY = YES; 306 | CLANG_WARN_ENUM_CONVERSION = YES; 307 | CLANG_WARN_INT_CONVERSION = YES; 308 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 309 | CLANG_WARN_UNREACHABLE_CODE = YES; 310 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 311 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; 312 | COPY_PHASE_STRIP = NO; 313 | DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; 314 | ENABLE_STRICT_OBJC_MSGSEND = YES; 315 | GCC_C_LANGUAGE_STANDARD = gnu99; 316 | GCC_DYNAMIC_NO_PIC = NO; 317 | GCC_NO_COMMON_BLOCKS = YES; 318 | GCC_OPTIMIZATION_LEVEL = 0; 319 | GCC_PREPROCESSOR_DEFINITIONS = ( 320 | "DEBUG=1", 321 | "$(inherited)", 322 | ); 323 | GCC_SYMBOLS_PRIVATE_EXTERN = NO; 324 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 325 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 326 | GCC_WARN_UNDECLARED_SELECTOR = YES; 327 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 328 | GCC_WARN_UNUSED_FUNCTION = YES; 329 | GCC_WARN_UNUSED_VARIABLE = YES; 330 | IPHONEOS_DEPLOYMENT_TARGET = 8.3; 331 | MTL_ENABLE_DEBUG_INFO = YES; 332 | ONLY_ACTIVE_ARCH = YES; 333 | SDKROOT = iphoneos; 334 | TARGETED_DEVICE_FAMILY = "1,2"; 335 | }; 336 | name = Debug; 337 | }; 338 | 255A29921AE02CF6002B62BA /* Release */ = { 339 | isa = XCBuildConfiguration; 340 | buildSettings = { 341 | ALWAYS_SEARCH_USER_PATHS = NO; 342 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; 343 | CLANG_CXX_LIBRARY = "libc++"; 344 | CLANG_ENABLE_MODULES = YES; 345 | CLANG_ENABLE_OBJC_ARC = YES; 346 | CLANG_WARN_BOOL_CONVERSION = YES; 347 | CLANG_WARN_CONSTANT_CONVERSION = YES; 348 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 349 | CLANG_WARN_EMPTY_BODY = YES; 350 | CLANG_WARN_ENUM_CONVERSION = YES; 351 | CLANG_WARN_INT_CONVERSION = YES; 352 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 353 | CLANG_WARN_UNREACHABLE_CODE = YES; 354 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 355 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; 356 | COPY_PHASE_STRIP = NO; 357 | DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; 358 | ENABLE_NS_ASSERTIONS = NO; 359 | ENABLE_STRICT_OBJC_MSGSEND = YES; 360 | GCC_C_LANGUAGE_STANDARD = gnu99; 361 | GCC_NO_COMMON_BLOCKS = YES; 362 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 363 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 364 | GCC_WARN_UNDECLARED_SELECTOR = YES; 365 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 366 | GCC_WARN_UNUSED_FUNCTION = YES; 367 | GCC_WARN_UNUSED_VARIABLE = YES; 368 | IPHONEOS_DEPLOYMENT_TARGET = 8.3; 369 | MTL_ENABLE_DEBUG_INFO = NO; 370 | SDKROOT = iphoneos; 371 | TARGETED_DEVICE_FAMILY = "1,2"; 372 | VALIDATE_PRODUCT = YES; 373 | }; 374 | name = Release; 375 | }; 376 | 255A29941AE02CF6002B62BA /* Debug */ = { 377 | isa = XCBuildConfiguration; 378 | buildSettings = { 379 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 380 | INFOPLIST_FILE = MetroCollectionLayoutSample/Info.plist; 381 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; 382 | PRODUCT_NAME = "$(TARGET_NAME)"; 383 | }; 384 | name = Debug; 385 | }; 386 | 255A29951AE02CF6002B62BA /* Release */ = { 387 | isa = XCBuildConfiguration; 388 | buildSettings = { 389 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 390 | INFOPLIST_FILE = MetroCollectionLayoutSample/Info.plist; 391 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; 392 | PRODUCT_NAME = "$(TARGET_NAME)"; 393 | }; 394 | name = Release; 395 | }; 396 | 255A29971AE02CF6002B62BA /* Debug */ = { 397 | isa = XCBuildConfiguration; 398 | buildSettings = { 399 | BUNDLE_LOADER = "$(TEST_HOST)"; 400 | FRAMEWORK_SEARCH_PATHS = ( 401 | "$(SDKROOT)/Developer/Library/Frameworks", 402 | "$(inherited)", 403 | ); 404 | GCC_PREPROCESSOR_DEFINITIONS = ( 405 | "DEBUG=1", 406 | "$(inherited)", 407 | ); 408 | INFOPLIST_FILE = MetroCollectionLayoutSampleTests/Info.plist; 409 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; 410 | PRODUCT_NAME = "$(TARGET_NAME)"; 411 | TEST_HOST = "$(BUILT_PRODUCTS_DIR)/MetroCollectionLayoutSample.app/MetroCollectionLayoutSample"; 412 | }; 413 | name = Debug; 414 | }; 415 | 255A29981AE02CF6002B62BA /* Release */ = { 416 | isa = XCBuildConfiguration; 417 | buildSettings = { 418 | BUNDLE_LOADER = "$(TEST_HOST)"; 419 | FRAMEWORK_SEARCH_PATHS = ( 420 | "$(SDKROOT)/Developer/Library/Frameworks", 421 | "$(inherited)", 422 | ); 423 | INFOPLIST_FILE = MetroCollectionLayoutSampleTests/Info.plist; 424 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; 425 | PRODUCT_NAME = "$(TARGET_NAME)"; 426 | TEST_HOST = "$(BUILT_PRODUCTS_DIR)/MetroCollectionLayoutSample.app/MetroCollectionLayoutSample"; 427 | }; 428 | name = Release; 429 | }; 430 | /* End XCBuildConfiguration section */ 431 | 432 | /* Begin XCConfigurationList section */ 433 | 255A296B1AE02CF6002B62BA /* Build configuration list for PBXProject "MetroCollectionLayoutSample" */ = { 434 | isa = XCConfigurationList; 435 | buildConfigurations = ( 436 | 255A29911AE02CF6002B62BA /* Debug */, 437 | 255A29921AE02CF6002B62BA /* Release */, 438 | ); 439 | defaultConfigurationIsVisible = 0; 440 | defaultConfigurationName = Release; 441 | }; 442 | 255A29931AE02CF6002B62BA /* Build configuration list for PBXNativeTarget "MetroCollectionLayoutSample" */ = { 443 | isa = XCConfigurationList; 444 | buildConfigurations = ( 445 | 255A29941AE02CF6002B62BA /* Debug */, 446 | 255A29951AE02CF6002B62BA /* Release */, 447 | ); 448 | defaultConfigurationIsVisible = 0; 449 | defaultConfigurationName = Release; 450 | }; 451 | 255A29961AE02CF6002B62BA /* Build configuration list for PBXNativeTarget "MetroCollectionLayoutSampleTests" */ = { 452 | isa = XCConfigurationList; 453 | buildConfigurations = ( 454 | 255A29971AE02CF6002B62BA /* Debug */, 455 | 255A29981AE02CF6002B62BA /* Release */, 456 | ); 457 | defaultConfigurationIsVisible = 0; 458 | defaultConfigurationName = Release; 459 | }; 460 | /* End XCConfigurationList section */ 461 | }; 462 | rootObject = 255A29681AE02CF6002B62BA /* Project object */; 463 | } 464 | --------------------------------------------------------------------------------