SafeHelperCollectionView.m 2.0 KB
//
//  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