// // HomeGoodBookCell.m // smartRhino // // Created by niuzhen on 2020/5/20. // Copyright © 2020 tederen. All rights reserved. // #import "HomeGoodBookCell.h" #import "BookHomeSubCell.h" #import "HomeGoodBookCollectCell.h" @implementation HomeGoodBookCell - (void)awakeFromNib { [super awakeFromNib]; self.collectionView.delegate = self; self.collectionView.dataSource = self; self.collectionView.showsVerticalScrollIndicator = NO; self.collectionView.showsHorizontalScrollIndicator = NO; [self.collectionView registerNib:[UINib nibWithNibName:@"BookHomeSubCell" bundle:nil] forCellWithReuseIdentifier:@"BookHomeSubCell"]; [self.collectionView registerNib:[UINib nibWithNibName:@"HomeGoodBookCollectCell" bundle:nil] forCellWithReuseIdentifier:@"HomeGoodBookCollectCell"]; } - (void)setSelected:(BOOL)selected animated:(BOOL)animated { [super setSelected:selected animated:animated]; // Configure the view for the selected state } + (HomeGoodBookCell *)configCell:(UITableView *)tableView indexPath:(NSIndexPath *)indexPath{ static NSString *cellIdentifer = @"HomeGoodBookCell"; HomeGoodBookCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifer]; if (cell == nil) { cell = [[[NSBundle mainBundle] loadNibNamed:@"HomeGoodBookCell" owner:nil options:nil] objectAtIndex:0]; } return cell; } - (void)setDataWithItem:(NSInteger)Item isUnUser:(BOOL)isUser { self.type = Item % 2 == 0 ? 0 : 1; if (self.type == 0) { self.collectH.constant = 101.f * 3; UICollectionViewFlowLayout * layout = [[UICollectionViewFlowLayout alloc]init]; layout.sectionInset = UIEdgeInsetsMake(0, 0, 0, 0); [self.collectionView setCollectionViewLayout:layout]; }else{ self.collectH.constant = 170.f * 2; UICollectionViewFlowLayout * layout = [[UICollectionViewFlowLayout alloc]init]; layout.sectionInset = UIEdgeInsetsMake(0, 15, 0, 15); [self.collectionView setCollectionViewLayout:layout]; } [self.collectionView setContentOffset:CGPointZero animated:NO]; [self.collectionView reloadData]; WS(weakSelf); dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.2 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{ [weakSelf.collectionView reloadData]; }); } - (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout minimumLineSpacingForSectionAtIndex:(NSInteger)section { return 0.f; } - (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout minimumInteritemSpacingForSectionAtIndex:(NSInteger)section { return self.type == 0 ? 0.f : 15.f; } - (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section { return self.type == 0 ? 3 : 6; } - (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView { return 1; } -(CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath { if (self.type == 0) { return CGSizeMake(SCREEN_WIDTH, 101); }else{ return CGSizeMake((SCREEN_WIDTH - 60) / 3, 170); } } - (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath { if (self.type == 0) { BookHomeSubCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"BookHomeSubCell" forIndexPath:indexPath]; [cell setData]; return cell; }else{ HomeGoodBookCollectCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"HomeGoodBookCollectCell" forIndexPath:indexPath]; return cell; } } - (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath { if (self.ClickIndexBlock) { self.ClickIndexBlock(); } } @end