SafeHelperCollectionView.m
2.0 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
//
// SafeHelperCollectionView.m
// DreamSleep
//
// Created by peter on 2022/4/12.
//
#import "SafeHelperCollectionView.h"
#import "SafeHelperCollectionViewCell.h"
@interface SafeHelperCollectionView () <UICollectionViewDelegate, UICollectionViewDataSource>
@property (nonatomic, strong) NSIndexPath *cellIndexPath;
@end
@implementation SafeHelperCollectionView
- (instancetype)initCollectionViewWithIndexPath:(NSIndexPath *)indexPath {
self.cellIndexPath = indexPath;
CGFloat width = indexPath.row == 0 ? 100 : 90;
CGFloat height = indexPath.row == 0 ? 130 : 120;
UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc] init];
layout.sectionInset = UIEdgeInsetsMake(0, 0, 0, 10);
layout.itemSize = CGSizeMake(width, height);
layout.minimumLineSpacing = 12;
layout.scrollDirection = UICollectionViewScrollDirectionHorizontal;
if (self = [super initWithFrame:CGRectMake(0, 0, 0, height) collectionViewLayout:layout]) {
[self registerClass:[SafeHelperCollectionViewCell class] forCellWithReuseIdentifier:@"shCollectionViewCell"];
self.dk_backgroundColorPicker = DKColorPickerWithKey(VCViewBG);
self.showsHorizontalScrollIndicator = NO;
self.delegate = self;
self.dataSource = self;
}
return self;
}
#pragma mark - UICollectionViewDelegate && UICollectionViewDataSource
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
return 8;
}
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
SafeHelperCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"shCollectionViewCell" forIndexPath:indexPath];
[cell mockDatas:self.cellIndexPath];
return cell;
}
- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath {
NSLog(@"row:%ld", indexPath.row);
}
@end