├── HorizontallyPageableFlowLayoutGIF.gif
├── HorizontallyPageableFlowLayout.xcodeproj
├── xcuserdata
│ └── che.xcuserdatad
│ │ ├── xcdebugger
│ │ └── Breakpoints_v2.xcbkptlist
│ │ └── xcschemes
│ │ └── xcschememanagement.plist
├── project.xcworkspace
│ ├── contents.xcworkspacedata
│ └── xcshareddata
│ │ └── IDEWorkspaceChecks.plist
└── project.pbxproj
└── HorizontallyPageableFlowLayout
├── ViewController.h
├── AppDelegate.h
├── CollectionViewLabelCell.h
├── main.m
├── CollectionViewLabelCell.m
├── HorizontallyPageableFlowLayout
├── HorizontallyPageableFlowLayout.h
└── HorizontallyPageableFlowLayout.m
├── Info.plist
├── Base.lproj
├── Main.storyboard
└── LaunchScreen.storyboard
├── Assets.xcassets
└── AppIcon.appiconset
│ └── Contents.json
├── AppDelegate.m
├── CollectionViewLabelCell.xib
└── ViewController.m
/HorizontallyPageableFlowLayoutGIF.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ABChe/HorizontallyPageableFlowLayout/HEAD/HorizontallyPageableFlowLayoutGIF.gif
--------------------------------------------------------------------------------
/HorizontallyPageableFlowLayout.xcodeproj/xcuserdata/che.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 |
--------------------------------------------------------------------------------
/HorizontallyPageableFlowLayout.xcodeproj/project.xcworkspace/contents.xcworkspacedata:
--------------------------------------------------------------------------------
1 |
2 |
4 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/HorizontallyPageableFlowLayout/ViewController.h:
--------------------------------------------------------------------------------
1 | //
2 | // ViewController.h
3 | // HorizontallyPageableFlowLayout
4 | //
5 | // Created by 车 on 2018/1/16.
6 | // Copyright © 2018年 车. All rights reserved.
7 | //
8 |
9 | #import
10 |
11 | @interface ViewController : UIViewController
12 |
13 |
14 | @end
15 |
16 |
--------------------------------------------------------------------------------
/HorizontallyPageableFlowLayout.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | IDEDidComputeMac32BitWarning
6 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/HorizontallyPageableFlowLayout/AppDelegate.h:
--------------------------------------------------------------------------------
1 | //
2 | // AppDelegate.h
3 | // HorizontallyPageableFlowLayout
4 | //
5 | // Created by 车 on 2018/1/16.
6 | // Copyright © 2018年 车. 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 |
--------------------------------------------------------------------------------
/HorizontallyPageableFlowLayout/CollectionViewLabelCell.h:
--------------------------------------------------------------------------------
1 | //
2 | // CollectionViewLabelCell.h
3 | // HorizontallyPageableFlowLayout
4 | //
5 | // Created by 车 on 2018/1/16.
6 | // Copyright © 2018年 车. All rights reserved.
7 | //
8 |
9 | #import
10 |
11 | @interface CollectionViewLabelCell : UICollectionViewCell
12 |
13 | @property (weak, nonatomic) IBOutlet UILabel *labelTitle;
14 |
15 | @end
16 |
--------------------------------------------------------------------------------
/HorizontallyPageableFlowLayout/main.m:
--------------------------------------------------------------------------------
1 | //
2 | // main.m
3 | // HorizontallyPageableFlowLayout
4 | //
5 | // Created by 车 on 2018/1/16.
6 | // Copyright © 2018年 车. 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 |
--------------------------------------------------------------------------------
/HorizontallyPageableFlowLayout/CollectionViewLabelCell.m:
--------------------------------------------------------------------------------
1 | //
2 | // CollectionViewLabelCell.m
3 | // HorizontallyPageableFlowLayout
4 | //
5 | // Created by 车 on 2018/1/16.
6 | // Copyright © 2018年 车. All rights reserved.
7 | //
8 |
9 | #import "CollectionViewLabelCell.h"
10 |
11 | @implementation CollectionViewLabelCell
12 |
13 | - (void)awakeFromNib {
14 | [super awakeFromNib];
15 | // Initialization code
16 | }
17 |
18 | @end
19 |
--------------------------------------------------------------------------------
/HorizontallyPageableFlowLayout.xcodeproj/xcuserdata/che.xcuserdatad/xcschemes/xcschememanagement.plist:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | SchemeUserState
6 |
7 | HorizontallyPageableFlowLayout.xcscheme
8 |
9 | orderHint
10 | 0
11 |
12 |
13 |
14 |
15 |
--------------------------------------------------------------------------------
/HorizontallyPageableFlowLayout/HorizontallyPageableFlowLayout/HorizontallyPageableFlowLayout.h:
--------------------------------------------------------------------------------
1 | //
2 | // HorizontallyPageableFlowLayout.h
3 | // HorizontallyPageableFlowLayout
4 | //
5 | // Created by 车 on 2018/1/16.
6 | // Copyright © 2018年 车. All rights reserved.
7 | //
8 |
9 | #import
10 |
11 | @interface HorizontallyPageableFlowLayout : UICollectionViewFlowLayout
12 |
13 | - (instancetype)initWithItemCountPerRow:(NSInteger)itemCountPerRow
14 | maxRowCount:(NSInteger)maxRowCount;
15 |
16 | @end
17 |
--------------------------------------------------------------------------------
/HorizontallyPageableFlowLayout/Info.plist:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | CFBundleDevelopmentRegion
6 | $(DEVELOPMENT_LANGUAGE)
7 | CFBundleExecutable
8 | $(EXECUTABLE_NAME)
9 | CFBundleIdentifier
10 | $(PRODUCT_BUNDLE_IDENTIFIER)
11 | CFBundleInfoDictionaryVersion
12 | 6.0
13 | CFBundleName
14 | $(PRODUCT_NAME)
15 | CFBundlePackageType
16 | APPL
17 | CFBundleShortVersionString
18 | 1.0
19 | CFBundleVersion
20 | 1
21 | LSRequiresIPhoneOS
22 |
23 | UILaunchStoryboardName
24 | LaunchScreen
25 | UIMainStoryboardFile
26 | Main
27 | UIRequiredDeviceCapabilities
28 |
29 | armv7
30 |
31 | UISupportedInterfaceOrientations
32 |
33 | UIInterfaceOrientationPortrait
34 | UIInterfaceOrientationLandscapeLeft
35 | UIInterfaceOrientationLandscapeRight
36 |
37 | UISupportedInterfaceOrientations~ipad
38 |
39 | UIInterfaceOrientationPortrait
40 | UIInterfaceOrientationPortraitUpsideDown
41 | UIInterfaceOrientationLandscapeLeft
42 | UIInterfaceOrientationLandscapeRight
43 |
44 |
45 |
46 |
--------------------------------------------------------------------------------
/HorizontallyPageableFlowLayout/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 |
--------------------------------------------------------------------------------
/HorizontallyPageableFlowLayout/Base.lproj/LaunchScreen.storyboard:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
--------------------------------------------------------------------------------
/HorizontallyPageableFlowLayout/Assets.xcassets/AppIcon.appiconset/Contents.json:
--------------------------------------------------------------------------------
1 | {
2 | "images" : [
3 | {
4 | "idiom" : "iphone",
5 | "size" : "20x20",
6 | "scale" : "2x"
7 | },
8 | {
9 | "idiom" : "iphone",
10 | "size" : "20x20",
11 | "scale" : "3x"
12 | },
13 | {
14 | "idiom" : "iphone",
15 | "size" : "29x29",
16 | "scale" : "2x"
17 | },
18 | {
19 | "idiom" : "iphone",
20 | "size" : "29x29",
21 | "scale" : "3x"
22 | },
23 | {
24 | "idiom" : "iphone",
25 | "size" : "40x40",
26 | "scale" : "2x"
27 | },
28 | {
29 | "idiom" : "iphone",
30 | "size" : "40x40",
31 | "scale" : "3x"
32 | },
33 | {
34 | "idiom" : "iphone",
35 | "size" : "60x60",
36 | "scale" : "2x"
37 | },
38 | {
39 | "idiom" : "iphone",
40 | "size" : "60x60",
41 | "scale" : "3x"
42 | },
43 | {
44 | "idiom" : "ipad",
45 | "size" : "20x20",
46 | "scale" : "1x"
47 | },
48 | {
49 | "idiom" : "ipad",
50 | "size" : "20x20",
51 | "scale" : "2x"
52 | },
53 | {
54 | "idiom" : "ipad",
55 | "size" : "29x29",
56 | "scale" : "1x"
57 | },
58 | {
59 | "idiom" : "ipad",
60 | "size" : "29x29",
61 | "scale" : "2x"
62 | },
63 | {
64 | "idiom" : "ipad",
65 | "size" : "40x40",
66 | "scale" : "1x"
67 | },
68 | {
69 | "idiom" : "ipad",
70 | "size" : "40x40",
71 | "scale" : "2x"
72 | },
73 | {
74 | "idiom" : "ipad",
75 | "size" : "76x76",
76 | "scale" : "1x"
77 | },
78 | {
79 | "idiom" : "ipad",
80 | "size" : "76x76",
81 | "scale" : "2x"
82 | },
83 | {
84 | "idiom" : "ipad",
85 | "size" : "83.5x83.5",
86 | "scale" : "2x"
87 | }
88 | ],
89 | "info" : {
90 | "version" : 1,
91 | "author" : "xcode"
92 | }
93 | }
--------------------------------------------------------------------------------
/HorizontallyPageableFlowLayout/AppDelegate.m:
--------------------------------------------------------------------------------
1 | //
2 | // AppDelegate.m
3 | // HorizontallyPageableFlowLayout
4 | //
5 | // Created by 车 on 2018/1/16.
6 | // Copyright © 2018年 车. 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 |
24 | - (void)applicationWillResignActive:(UIApplication *)application {
25 | // 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.
26 | // Use this method to pause ongoing tasks, disable timers, and invalidate graphics rendering callbacks. Games should use this method to pause the game.
27 | }
28 |
29 |
30 | - (void)applicationDidEnterBackground:(UIApplication *)application {
31 | // 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.
32 | // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
33 | }
34 |
35 |
36 | - (void)applicationWillEnterForeground:(UIApplication *)application {
37 | // Called as part of the transition from the background to the active state; here you can undo many of the changes made on entering the background.
38 | }
39 |
40 |
41 | - (void)applicationDidBecomeActive:(UIApplication *)application {
42 | // 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.
43 | }
44 |
45 |
46 | - (void)applicationWillTerminate:(UIApplication *)application {
47 | // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
48 | }
49 |
50 |
51 | @end
52 |
--------------------------------------------------------------------------------
/HorizontallyPageableFlowLayout/CollectionViewLabelCell.xib:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
--------------------------------------------------------------------------------
/HorizontallyPageableFlowLayout/HorizontallyPageableFlowLayout/HorizontallyPageableFlowLayout.m:
--------------------------------------------------------------------------------
1 | //
2 | // HorizontallyPageableFlowLayout.m
3 | // HorizontallyPageableFlowLayout
4 | //
5 | // Created by 车 on 2018/1/16.
6 | // Copyright © 2018年 车. All rights reserved.
7 | //
8 |
9 | #import "HorizontallyPageableFlowLayout.h"
10 |
11 | @interface HorizontallyPageableFlowLayout ()
12 |
13 | // 存放全部item布局信息的数组
14 | @property (nonatomic, strong) NSMutableArray *attributesArray;
15 |
16 | // 行数
17 | @property (nonatomic, assign) NSInteger rowCount;
18 | // item每行个数
19 | @property (nonatomic, assign) NSInteger itemCountPerRow;
20 | // item总数
21 | @property (nonatomic, assign) NSInteger itemCountTotal;
22 | // 页数
23 | @property (nonatomic, assign) NSInteger pageCount;
24 | // 最大行数
25 | @property (nonatomic, assign) NSInteger maxRowCount;
26 |
27 | @end
28 |
29 |
30 | @implementation HorizontallyPageableFlowLayout
31 |
32 | - (instancetype)initWithItemCountPerRow:(NSInteger)itemCountPerRow maxRowCount:(NSInteger)maxRowCount {
33 | self = [super init];
34 | if (self) {
35 | self.attributesArray = [NSMutableArray array];
36 | self.itemCountPerRow = itemCountPerRow;
37 | self.maxRowCount = maxRowCount;
38 | self.scrollDirection = UICollectionViewScrollDirectionHorizontal;
39 | }
40 | return self;
41 | }
42 |
43 | - (void)prepareLayout {
44 | [super prepareLayout];
45 | self.itemCountTotal = [self.collectionView numberOfItemsInSection:0];
46 |
47 | // rowCount
48 | if (self.itemCountTotal == 0) {
49 | self.rowCount = 0;
50 | } else if ((ceilf(self.itemCountTotal / (float)self.itemCountPerRow)) > self.maxRowCount) {
51 | self.rowCount = self.maxRowCount;
52 | } else {
53 | self.rowCount = ceilf(self.itemCountTotal / (float)self.itemCountPerRow);
54 | }
55 |
56 | self.pageCount = self.itemCountTotal ? ceilf(self.itemCountTotal / (float)(self.itemCountPerRow * self.maxRowCount)) : 0;
57 |
58 | for (NSInteger i = 0; i < self.itemCountTotal; i++) {
59 | NSIndexPath *indexPath = [NSIndexPath indexPathForItem:i inSection:0];
60 | UICollectionViewLayoutAttributes *attributes = [self layoutAttributesForItemAtIndexPath:indexPath];
61 | [self.attributesArray addObject:attributes];
62 | }
63 | }
64 |
65 | - (UICollectionViewLayoutAttributes *)layoutAttributesForItemAtIndexPath:(NSIndexPath *)indexPath {
66 | NSInteger item = indexPath.item;
67 |
68 | /*
69 | 0 2 4 ---\ 0 1 2
70 | 1 3 5 ---/ 3 4 5 计算转换后对应的item 原来'4'的item为4,转换后为3
71 | */
72 | NSInteger page = item / (self.itemCountPerRow * self.maxRowCount);
73 | // 计算目标item的位置 x 横向偏移 y 竖向偏移
74 | NSUInteger x = item % self.itemCountPerRow + page * self.itemCountPerRow;
75 | NSUInteger y = item / self.itemCountPerRow - page * self.rowCount;
76 | // 根据偏移量计算item
77 | NSInteger newItem = x * self.rowCount + y;
78 | NSIndexPath *newIndexPath = [NSIndexPath indexPathForItem:newItem inSection:indexPath.section];
79 |
80 | UICollectionViewLayoutAttributes *newAttributes = [super layoutAttributesForItemAtIndexPath:newIndexPath];
81 | newAttributes.indexPath = indexPath;
82 |
83 | return newAttributes;
84 | }
85 |
86 | - (CGSize)collectionViewContentSize {
87 | if (!self.itemCountTotal) return CGSizeMake(0, 0);
88 |
89 | return CGSizeMake(self.pageCount * CGRectGetWidth(self.collectionView.frame), 0);
90 | }
91 |
92 | - (NSArray *)layoutAttributesForElementsInRect:(CGRect)rect {
93 | NSArray *attributes = [super layoutAttributesForElementsInRect:rect];
94 | NSMutableArray *array = [NSMutableArray array];
95 |
96 | for (UICollectionViewLayoutAttributes *attr1 in attributes) {
97 | for (UICollectionViewLayoutAttributes *attr2 in self.attributesArray) {
98 | if (attr1.indexPath.item == attr2.indexPath.item) {
99 | [array addObject:attr2];
100 | break;
101 | }
102 | }
103 | }
104 | return array;
105 | }
106 |
107 | @end
108 |
--------------------------------------------------------------------------------
/HorizontallyPageableFlowLayout/ViewController.m:
--------------------------------------------------------------------------------
1 | //
2 | // ViewController.m
3 | // HorizontallyPageableFlowLayout
4 | //
5 | // Created by 车 on 2018/1/16.
6 | // Copyright © 2018年 车. All rights reserved.
7 | //
8 |
9 | #import "ViewController.h"
10 | #import "HorizontallyPageableFlowLayout.h"
11 | #import "CollectionViewLabelCell.h"
12 |
13 | static const CGFloat kMaxRowCount = 2.f;
14 | static const CGFloat kItemCountPerRow = 4.f;
15 |
16 | @interface ViewController ()
17 |
18 | @property (nonatomic, strong) UIButton *addButton;
19 | @property (nonatomic, strong) UIButton *deleteButton;
20 | @property (nonatomic, strong) UICollectionView *collectionView;
21 |
22 | @property (nonatomic, strong) NSMutableArray *dataArray;
23 | @property (nonatomic, strong) HorizontallyPageableFlowLayout *layout;
24 |
25 | @end
26 |
27 |
28 | @implementation ViewController
29 |
30 | #pragma mark - LifeCycle
31 |
32 | - (void)viewDidLoad {
33 | [super viewDidLoad];
34 |
35 | [self.view addSubview:self.addButton];
36 | [self.view addSubview:self.deleteButton];
37 | [self.view addSubview:self.collectionView];
38 |
39 | [self reloadCollectionView];
40 | }
41 |
42 |
43 | #pragma mark - UICollectionViewDelegate
44 |
45 | - (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
46 | NSInteger itemCount;
47 | if (self.dataArray.count == 0) {
48 | itemCount = 0;
49 | } else if (self.dataArray.count / (kMaxRowCount * kItemCountPerRow) > 1) {
50 | // 超过一页
51 | itemCount = kMaxRowCount * kItemCountPerRow * ceilf(self.dataArray.count / (kMaxRowCount * kItemCountPerRow));
52 | } else {
53 | itemCount = ceilf(self.dataArray.count / kItemCountPerRow) * kItemCountPerRow;
54 | }
55 | return itemCount;
56 | }
57 |
58 | - (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
59 | CollectionViewLabelCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:[CollectionViewLabelCell description] forIndexPath:indexPath];
60 |
61 | if (indexPath.item < self.dataArray.count) {
62 | cell.backgroundColor = [UIColor lightGrayColor];
63 | cell.labelTitle.text = self.dataArray[indexPath.item];
64 | cell.labelTitle.textColor = [UIColor grayColor];
65 | }else{
66 | cell.backgroundColor = [UIColor clearColor];
67 | cell.labelTitle.text = @"";
68 | }
69 | return cell;
70 | }
71 |
72 |
73 | #pragma mark - Method
74 |
75 | - (void)clickButton:(UIButton *)button {
76 | if (button.tag == 100) {
77 | // +
78 | if (self.dataArray.count) {
79 | NSString *title = self.dataArray.lastObject;
80 | NSInteger addNumber = title.integerValue + 1;
81 | [self.dataArray addObject:[NSString stringWithFormat:@"%ld", addNumber]];
82 | } else {
83 | [self.dataArray addObject:@"0"];
84 | }
85 |
86 | } else {
87 | // -
88 | if (self.dataArray.count) {
89 | [self.dataArray removeLastObject];
90 | } else {
91 | return;
92 | }
93 | }
94 |
95 | [self reloadCollectionView];
96 | }
97 |
98 | - (void)reloadCollectionView {
99 | NSInteger rowCount;
100 | if (self.dataArray.count == 0) {
101 | rowCount = 0;
102 | } else if (self.dataArray.count / (kMaxRowCount * kItemCountPerRow) > 1) {
103 | rowCount = kMaxRowCount;
104 | } else {
105 | rowCount = ceil(self.dataArray.count / kItemCountPerRow);
106 | }
107 |
108 | CGFloat collectionViewHeight = rowCount * CGRectGetWidth(self.view.frame) / kItemCountPerRow;
109 | self.collectionView.frame = CGRectMake(0, 120, CGRectGetWidth(self.view.frame), collectionViewHeight);
110 |
111 | [self.collectionView reloadData];
112 | }
113 |
114 |
115 | #pragma mark - Lazyloading
116 |
117 | - (UIButton *)addButton {
118 | if (_addButton == nil) {
119 | _addButton = [[UIButton alloc] initWithFrame:CGRectMake(40, 64, 50, 50)];
120 | _addButton.tag = 100;
121 | [_addButton setTitle:@"+" forState:UIControlStateNormal];
122 | [_addButton setTitleColor:[UIColor redColor] forState:UIControlStateNormal];
123 | _addButton.backgroundColor = [UIColor lightGrayColor];
124 | [_addButton addTarget:self action:@selector(clickButton:) forControlEvents:UIControlEventTouchUpInside];
125 | }
126 | return _addButton;
127 | }
128 |
129 | - (UIButton *)deleteButton {
130 | if (_deleteButton == nil) {
131 | _deleteButton = [[UIButton alloc] initWithFrame:CGRectMake(CGRectGetWidth(self.view.frame) - 50 - 40, 64, 50, 50)];
132 | _deleteButton.tag = 101;
133 | [_deleteButton setTitle:@"-" forState:UIControlStateNormal];
134 | [_deleteButton setTitleColor:[UIColor redColor] forState:UIControlStateNormal];
135 | _deleteButton.backgroundColor = [UIColor lightGrayColor];
136 | [_deleteButton addTarget:self action:@selector(clickButton:) forControlEvents:UIControlEventTouchUpInside];
137 | }
138 | return _deleteButton;
139 | }
140 |
141 | - (UICollectionView *)collectionView {
142 | if (_collectionView == nil) {
143 | CGRect frame = CGRectMake(0, 120, CGRectGetWidth(self.view.frame), CGRectGetWidth(self.view.frame) / kItemCountPerRow * kMaxRowCount);
144 | _collectionView = [[UICollectionView alloc] initWithFrame:frame collectionViewLayout:self.layout];
145 | _collectionView.delegate = self;
146 | _collectionView.dataSource = self;
147 | _collectionView.scrollEnabled = YES;
148 | _collectionView.pagingEnabled = YES;
149 | [_collectionView registerNib:[UINib nibWithNibName:[CollectionViewLabelCell description] bundle:nil] forCellWithReuseIdentifier:[CollectionViewLabelCell description]];
150 | _collectionView.backgroundColor = [UIColor cyanColor];
151 | }
152 | return _collectionView;
153 | }
154 |
155 | - (HorizontallyPageableFlowLayout *)layout {
156 | if (_layout == nil) {
157 | _layout = [[HorizontallyPageableFlowLayout alloc] initWithItemCountPerRow:kItemCountPerRow maxRowCount:kMaxRowCount];
158 | _layout.minimumLineSpacing = 0;
159 | _layout.minimumInteritemSpacing = 0;
160 | _layout.itemSize = CGSizeMake(CGRectGetWidth(self.view.frame) / kItemCountPerRow, CGRectGetWidth(self.view.frame) / kItemCountPerRow);
161 | }
162 | return _layout;
163 | }
164 |
165 | - (NSMutableArray *)dataArray {
166 | if (_dataArray == nil) {
167 | _dataArray = [NSMutableArray array];
168 | for (int i = 0; i < 10; i++) {
169 | [_dataArray addObject:[NSString stringWithFormat:@"%d",i]];
170 | }
171 | }
172 | return _dataArray;
173 | }
174 |
175 | @end
176 |
--------------------------------------------------------------------------------
/HorizontallyPageableFlowLayout.xcodeproj/project.pbxproj:
--------------------------------------------------------------------------------
1 | // !$*UTF8*$!
2 | {
3 | archiveVersion = 1;
4 | classes = {
5 | };
6 | objectVersion = 48;
7 | objects = {
8 |
9 | /* Begin PBXBuildFile section */
10 | F250FA8C200E245C0078C22C /* AppDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = F250FA8B200E245C0078C22C /* AppDelegate.m */; };
11 | F250FA8F200E245C0078C22C /* ViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = F250FA8E200E245C0078C22C /* ViewController.m */; };
12 | F250FA92200E245C0078C22C /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = F250FA90200E245C0078C22C /* Main.storyboard */; };
13 | F250FA94200E245C0078C22C /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = F250FA93200E245C0078C22C /* Assets.xcassets */; };
14 | F250FA97200E245C0078C22C /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = F250FA95200E245C0078C22C /* LaunchScreen.storyboard */; };
15 | F250FA9A200E245C0078C22C /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = F250FA99200E245C0078C22C /* main.m */; };
16 | F250FAA8200E25430078C22C /* CollectionViewLabelCell.m in Sources */ = {isa = PBXBuildFile; fileRef = F250FAA6200E25430078C22C /* CollectionViewLabelCell.m */; };
17 | F250FAA9200E25430078C22C /* CollectionViewLabelCell.xib in Resources */ = {isa = PBXBuildFile; fileRef = F250FAA7200E25430078C22C /* CollectionViewLabelCell.xib */; };
18 | F250FAAD200E26410078C22C /* HorizontallyPageableFlowLayout.m in Sources */ = {isa = PBXBuildFile; fileRef = F250FAAC200E26410078C22C /* HorizontallyPageableFlowLayout.m */; };
19 | /* End PBXBuildFile section */
20 |
21 | /* Begin PBXFileReference section */
22 | F250FA87200E245C0078C22C /* HorizontallyPageableFlowLayout.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = HorizontallyPageableFlowLayout.app; sourceTree = BUILT_PRODUCTS_DIR; };
23 | F250FA8A200E245C0078C22C /* AppDelegate.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = AppDelegate.h; sourceTree = ""; };
24 | F250FA8B200E245C0078C22C /* AppDelegate.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = AppDelegate.m; sourceTree = ""; };
25 | F250FA8D200E245C0078C22C /* ViewController.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = ViewController.h; sourceTree = ""; };
26 | F250FA8E200E245C0078C22C /* ViewController.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = ViewController.m; sourceTree = ""; };
27 | F250FA91200E245C0078C22C /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/Main.storyboard; sourceTree = ""; };
28 | F250FA93200E245C0078C22C /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = ""; };
29 | F250FA96200E245C0078C22C /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/LaunchScreen.storyboard; sourceTree = ""; };
30 | F250FA98200E245C0078C22C /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; };
31 | F250FA99200E245C0078C22C /* main.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = main.m; sourceTree = ""; };
32 | F250FAA5200E25430078C22C /* CollectionViewLabelCell.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = CollectionViewLabelCell.h; sourceTree = ""; };
33 | F250FAA6200E25430078C22C /* CollectionViewLabelCell.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = CollectionViewLabelCell.m; sourceTree = ""; };
34 | F250FAA7200E25430078C22C /* CollectionViewLabelCell.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = CollectionViewLabelCell.xib; sourceTree = ""; };
35 | F250FAAB200E26410078C22C /* HorizontallyPageableFlowLayout.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = HorizontallyPageableFlowLayout.h; sourceTree = ""; };
36 | F250FAAC200E26410078C22C /* HorizontallyPageableFlowLayout.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = HorizontallyPageableFlowLayout.m; sourceTree = ""; };
37 | /* End PBXFileReference section */
38 |
39 | /* Begin PBXFrameworksBuildPhase section */
40 | F250FA84200E245C0078C22C /* Frameworks */ = {
41 | isa = PBXFrameworksBuildPhase;
42 | buildActionMask = 2147483647;
43 | files = (
44 | );
45 | runOnlyForDeploymentPostprocessing = 0;
46 | };
47 | /* End PBXFrameworksBuildPhase section */
48 |
49 | /* Begin PBXGroup section */
50 | F250FA7E200E245C0078C22C = {
51 | isa = PBXGroup;
52 | children = (
53 | F250FA89200E245C0078C22C /* HorizontallyPageableFlowLayout */,
54 | F250FA88200E245C0078C22C /* Products */,
55 | );
56 | sourceTree = "";
57 | };
58 | F250FA88200E245C0078C22C /* Products */ = {
59 | isa = PBXGroup;
60 | children = (
61 | F250FA87200E245C0078C22C /* HorizontallyPageableFlowLayout.app */,
62 | );
63 | name = Products;
64 | sourceTree = "";
65 | };
66 | F250FA89200E245C0078C22C /* HorizontallyPageableFlowLayout */ = {
67 | isa = PBXGroup;
68 | children = (
69 | F250FA8A200E245C0078C22C /* AppDelegate.h */,
70 | F250FA8B200E245C0078C22C /* AppDelegate.m */,
71 | F250FAAA200E26200078C22C /* HorizontallyPageableFlowLayout */,
72 | F250FA8D200E245C0078C22C /* ViewController.h */,
73 | F250FA8E200E245C0078C22C /* ViewController.m */,
74 | F250FAA5200E25430078C22C /* CollectionViewLabelCell.h */,
75 | F250FAA6200E25430078C22C /* CollectionViewLabelCell.m */,
76 | F250FAA7200E25430078C22C /* CollectionViewLabelCell.xib */,
77 | F250FA90200E245C0078C22C /* Main.storyboard */,
78 | F250FA93200E245C0078C22C /* Assets.xcassets */,
79 | F250FA95200E245C0078C22C /* LaunchScreen.storyboard */,
80 | F250FA98200E245C0078C22C /* Info.plist */,
81 | F250FA99200E245C0078C22C /* main.m */,
82 | );
83 | path = HorizontallyPageableFlowLayout;
84 | sourceTree = "";
85 | };
86 | F250FAAA200E26200078C22C /* HorizontallyPageableFlowLayout */ = {
87 | isa = PBXGroup;
88 | children = (
89 | F250FAAB200E26410078C22C /* HorizontallyPageableFlowLayout.h */,
90 | F250FAAC200E26410078C22C /* HorizontallyPageableFlowLayout.m */,
91 | );
92 | path = HorizontallyPageableFlowLayout;
93 | sourceTree = "";
94 | };
95 | /* End PBXGroup section */
96 |
97 | /* Begin PBXNativeTarget section */
98 | F250FA86200E245C0078C22C /* HorizontallyPageableFlowLayout */ = {
99 | isa = PBXNativeTarget;
100 | buildConfigurationList = F250FA9D200E245C0078C22C /* Build configuration list for PBXNativeTarget "HorizontallyPageableFlowLayout" */;
101 | buildPhases = (
102 | F250FA83200E245C0078C22C /* Sources */,
103 | F250FA84200E245C0078C22C /* Frameworks */,
104 | F250FA85200E245C0078C22C /* Resources */,
105 | );
106 | buildRules = (
107 | );
108 | dependencies = (
109 | );
110 | name = HorizontallyPageableFlowLayout;
111 | productName = HorizontallyPageableFlowLayout;
112 | productReference = F250FA87200E245C0078C22C /* HorizontallyPageableFlowLayout.app */;
113 | productType = "com.apple.product-type.application";
114 | };
115 | /* End PBXNativeTarget section */
116 |
117 | /* Begin PBXProject section */
118 | F250FA7F200E245C0078C22C /* Project object */ = {
119 | isa = PBXProject;
120 | attributes = {
121 | LastUpgradeCheck = 0920;
122 | ORGANIZATIONNAME = "车";
123 | TargetAttributes = {
124 | F250FA86200E245C0078C22C = {
125 | CreatedOnToolsVersion = 9.2;
126 | ProvisioningStyle = Automatic;
127 | };
128 | };
129 | };
130 | buildConfigurationList = F250FA82200E245C0078C22C /* Build configuration list for PBXProject "HorizontallyPageableFlowLayout" */;
131 | compatibilityVersion = "Xcode 8.0";
132 | developmentRegion = en;
133 | hasScannedForEncodings = 0;
134 | knownRegions = (
135 | en,
136 | Base,
137 | );
138 | mainGroup = F250FA7E200E245C0078C22C;
139 | productRefGroup = F250FA88200E245C0078C22C /* Products */;
140 | projectDirPath = "";
141 | projectRoot = "";
142 | targets = (
143 | F250FA86200E245C0078C22C /* HorizontallyPageableFlowLayout */,
144 | );
145 | };
146 | /* End PBXProject section */
147 |
148 | /* Begin PBXResourcesBuildPhase section */
149 | F250FA85200E245C0078C22C /* Resources */ = {
150 | isa = PBXResourcesBuildPhase;
151 | buildActionMask = 2147483647;
152 | files = (
153 | F250FA97200E245C0078C22C /* LaunchScreen.storyboard in Resources */,
154 | F250FA94200E245C0078C22C /* Assets.xcassets in Resources */,
155 | F250FA92200E245C0078C22C /* Main.storyboard in Resources */,
156 | F250FAA9200E25430078C22C /* CollectionViewLabelCell.xib in Resources */,
157 | );
158 | runOnlyForDeploymentPostprocessing = 0;
159 | };
160 | /* End PBXResourcesBuildPhase section */
161 |
162 | /* Begin PBXSourcesBuildPhase section */
163 | F250FA83200E245C0078C22C /* Sources */ = {
164 | isa = PBXSourcesBuildPhase;
165 | buildActionMask = 2147483647;
166 | files = (
167 | F250FA8F200E245C0078C22C /* ViewController.m in Sources */,
168 | F250FA9A200E245C0078C22C /* main.m in Sources */,
169 | F250FAA8200E25430078C22C /* CollectionViewLabelCell.m in Sources */,
170 | F250FAAD200E26410078C22C /* HorizontallyPageableFlowLayout.m in Sources */,
171 | F250FA8C200E245C0078C22C /* AppDelegate.m in Sources */,
172 | );
173 | runOnlyForDeploymentPostprocessing = 0;
174 | };
175 | /* End PBXSourcesBuildPhase section */
176 |
177 | /* Begin PBXVariantGroup section */
178 | F250FA90200E245C0078C22C /* Main.storyboard */ = {
179 | isa = PBXVariantGroup;
180 | children = (
181 | F250FA91200E245C0078C22C /* Base */,
182 | );
183 | name = Main.storyboard;
184 | sourceTree = "";
185 | };
186 | F250FA95200E245C0078C22C /* LaunchScreen.storyboard */ = {
187 | isa = PBXVariantGroup;
188 | children = (
189 | F250FA96200E245C0078C22C /* Base */,
190 | );
191 | name = LaunchScreen.storyboard;
192 | sourceTree = "";
193 | };
194 | /* End PBXVariantGroup section */
195 |
196 | /* Begin XCBuildConfiguration section */
197 | F250FA9B200E245C0078C22C /* Debug */ = {
198 | isa = XCBuildConfiguration;
199 | buildSettings = {
200 | ALWAYS_SEARCH_USER_PATHS = NO;
201 | CLANG_ANALYZER_NONNULL = YES;
202 | CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE;
203 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++14";
204 | CLANG_CXX_LIBRARY = "libc++";
205 | CLANG_ENABLE_MODULES = YES;
206 | CLANG_ENABLE_OBJC_ARC = YES;
207 | CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES;
208 | CLANG_WARN_BOOL_CONVERSION = YES;
209 | CLANG_WARN_COMMA = YES;
210 | CLANG_WARN_CONSTANT_CONVERSION = YES;
211 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
212 | CLANG_WARN_DOCUMENTATION_COMMENTS = YES;
213 | CLANG_WARN_EMPTY_BODY = YES;
214 | CLANG_WARN_ENUM_CONVERSION = YES;
215 | CLANG_WARN_INFINITE_RECURSION = YES;
216 | CLANG_WARN_INT_CONVERSION = YES;
217 | CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES;
218 | CLANG_WARN_OBJC_LITERAL_CONVERSION = YES;
219 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
220 | CLANG_WARN_RANGE_LOOP_ANALYSIS = YES;
221 | CLANG_WARN_STRICT_PROTOTYPES = YES;
222 | CLANG_WARN_SUSPICIOUS_MOVE = YES;
223 | CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE;
224 | CLANG_WARN_UNREACHABLE_CODE = YES;
225 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
226 | CODE_SIGN_IDENTITY = "iPhone Developer";
227 | COPY_PHASE_STRIP = NO;
228 | DEBUG_INFORMATION_FORMAT = dwarf;
229 | ENABLE_STRICT_OBJC_MSGSEND = YES;
230 | ENABLE_TESTABILITY = YES;
231 | GCC_C_LANGUAGE_STANDARD = gnu11;
232 | GCC_DYNAMIC_NO_PIC = NO;
233 | GCC_NO_COMMON_BLOCKS = YES;
234 | GCC_OPTIMIZATION_LEVEL = 0;
235 | GCC_PREPROCESSOR_DEFINITIONS = (
236 | "DEBUG=1",
237 | "$(inherited)",
238 | );
239 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES;
240 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR;
241 | GCC_WARN_UNDECLARED_SELECTOR = YES;
242 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
243 | GCC_WARN_UNUSED_FUNCTION = YES;
244 | GCC_WARN_UNUSED_VARIABLE = YES;
245 | IPHONEOS_DEPLOYMENT_TARGET = 11.2;
246 | MTL_ENABLE_DEBUG_INFO = YES;
247 | ONLY_ACTIVE_ARCH = YES;
248 | SDKROOT = iphoneos;
249 | };
250 | name = Debug;
251 | };
252 | F250FA9C200E245C0078C22C /* Release */ = {
253 | isa = XCBuildConfiguration;
254 | buildSettings = {
255 | ALWAYS_SEARCH_USER_PATHS = NO;
256 | CLANG_ANALYZER_NONNULL = YES;
257 | CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE;
258 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++14";
259 | CLANG_CXX_LIBRARY = "libc++";
260 | CLANG_ENABLE_MODULES = YES;
261 | CLANG_ENABLE_OBJC_ARC = YES;
262 | CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES;
263 | CLANG_WARN_BOOL_CONVERSION = YES;
264 | CLANG_WARN_COMMA = YES;
265 | CLANG_WARN_CONSTANT_CONVERSION = YES;
266 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
267 | CLANG_WARN_DOCUMENTATION_COMMENTS = YES;
268 | CLANG_WARN_EMPTY_BODY = YES;
269 | CLANG_WARN_ENUM_CONVERSION = YES;
270 | CLANG_WARN_INFINITE_RECURSION = YES;
271 | CLANG_WARN_INT_CONVERSION = YES;
272 | CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES;
273 | CLANG_WARN_OBJC_LITERAL_CONVERSION = YES;
274 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
275 | CLANG_WARN_RANGE_LOOP_ANALYSIS = YES;
276 | CLANG_WARN_STRICT_PROTOTYPES = YES;
277 | CLANG_WARN_SUSPICIOUS_MOVE = YES;
278 | CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE;
279 | CLANG_WARN_UNREACHABLE_CODE = YES;
280 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
281 | CODE_SIGN_IDENTITY = "iPhone Developer";
282 | COPY_PHASE_STRIP = NO;
283 | DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym";
284 | ENABLE_NS_ASSERTIONS = NO;
285 | ENABLE_STRICT_OBJC_MSGSEND = YES;
286 | GCC_C_LANGUAGE_STANDARD = gnu11;
287 | GCC_NO_COMMON_BLOCKS = YES;
288 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES;
289 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR;
290 | GCC_WARN_UNDECLARED_SELECTOR = YES;
291 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
292 | GCC_WARN_UNUSED_FUNCTION = YES;
293 | GCC_WARN_UNUSED_VARIABLE = YES;
294 | IPHONEOS_DEPLOYMENT_TARGET = 11.2;
295 | MTL_ENABLE_DEBUG_INFO = NO;
296 | SDKROOT = iphoneos;
297 | VALIDATE_PRODUCT = YES;
298 | };
299 | name = Release;
300 | };
301 | F250FA9E200E245C0078C22C /* Debug */ = {
302 | isa = XCBuildConfiguration;
303 | buildSettings = {
304 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
305 | CODE_SIGN_STYLE = Automatic;
306 | INFOPLIST_FILE = HorizontallyPageableFlowLayout/Info.plist;
307 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
308 | PRODUCT_BUNDLE_IDENTIFIER = "-.HorizontallyPageableFlowLayout";
309 | PRODUCT_NAME = "$(TARGET_NAME)";
310 | TARGETED_DEVICE_FAMILY = "1,2";
311 | };
312 | name = Debug;
313 | };
314 | F250FA9F200E245C0078C22C /* Release */ = {
315 | isa = XCBuildConfiguration;
316 | buildSettings = {
317 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
318 | CODE_SIGN_STYLE = Automatic;
319 | INFOPLIST_FILE = HorizontallyPageableFlowLayout/Info.plist;
320 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
321 | PRODUCT_BUNDLE_IDENTIFIER = "-.HorizontallyPageableFlowLayout";
322 | PRODUCT_NAME = "$(TARGET_NAME)";
323 | TARGETED_DEVICE_FAMILY = "1,2";
324 | };
325 | name = Release;
326 | };
327 | /* End XCBuildConfiguration section */
328 |
329 | /* Begin XCConfigurationList section */
330 | F250FA82200E245C0078C22C /* Build configuration list for PBXProject "HorizontallyPageableFlowLayout" */ = {
331 | isa = XCConfigurationList;
332 | buildConfigurations = (
333 | F250FA9B200E245C0078C22C /* Debug */,
334 | F250FA9C200E245C0078C22C /* Release */,
335 | );
336 | defaultConfigurationIsVisible = 0;
337 | defaultConfigurationName = Release;
338 | };
339 | F250FA9D200E245C0078C22C /* Build configuration list for PBXNativeTarget "HorizontallyPageableFlowLayout" */ = {
340 | isa = XCConfigurationList;
341 | buildConfigurations = (
342 | F250FA9E200E245C0078C22C /* Debug */,
343 | F250FA9F200E245C0078C22C /* Release */,
344 | );
345 | defaultConfigurationIsVisible = 0;
346 | defaultConfigurationName = Release;
347 | };
348 | /* End XCConfigurationList section */
349 | };
350 | rootObject = F250FA7F200E245C0078C22C /* Project object */;
351 | }
352 |
--------------------------------------------------------------------------------