// // HomeUserPrivilegeCell.m // smartRhino // // Created by niuzhen on 2020/5/16. // Copyright © 2020 tederen. All rights reserved. // #import "HomeUserPrivilegeCell.h" #import "BookHomeSubCell.h" #import "BookHomeSubModel.h" @implementation HomeUserPrivilegeCell - (void)awakeFromNib { [super awakeFromNib]; self.lookBtn.layer.cornerRadius = 10.f; self.lookBtn.layer.borderWidth = 0.5f; self.lookBtn.layer.borderColor = UIColorHex(0xE0E0E0).CGColor; self.lookBtn.layer.masksToBounds = YES; 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"]; } - (void)setSelected:(BOOL)selected animated:(BOOL)animated { [super setSelected:selected animated:animated]; } + (HomeUserPrivilegeCell *)configCell:(UITableView *)tableView indexPath:(NSIndexPath *)indexPath{ static NSString *cellIdentifer = @"HomeUserPrivilegeCell"; HomeUserPrivilegeCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifer]; if (cell == nil) { cell = [[[NSBundle mainBundle] loadNibNamed:@"HomeUserPrivilegeCell" owner:nil options:nil] objectAtIndex:0]; } return cell; } - (void)setDataWithItem:(NSInteger)Item isUnUser:(BOOL)isUser model:(HomeSubModel *)model { self.model = model; self.TitleL.text = model.LabelName; self.collectH.constant = 109.f * model.Items.count; [self.contentView setBackgroundColor:Item % 2 == 0 ? UIColorHex(0xFFFFFF) : UIColorHex(0xF7F7F9)]; [self.collectionView setBackgroundColor:Item % 2 == 0 ? UIColorHex(0xFFFFFF) : UIColorHex(0xF7F7F9)]; UICollectionViewFlowLayout * layout = [[UICollectionViewFlowLayout alloc]init]; [self.collectionView setContentSize:CGSizeMake(SCREEN_WIDTH, 109 * model.Items.count)]; layout.sectionInset = UIEdgeInsetsMake(0, 0, 0, 0); [self.collectionView setCollectionViewLayout:layout]; [self.collectionView setContentOffset:CGPointZero animated:NO]; [self.collectionView reloadData]; self.ShowView.hidden = !isUser; if (isUser) { [self setShowBgColor]; } [self.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 0.f; } - (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section { return self.model.Items.count; } - (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView { return 1; } -(CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath { return CGSizeMake(SCREEN_WIDTH, 109); } - (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath { BookHomeSubCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"BookHomeSubCell" forIndexPath:indexPath]; NSDictionary * dict = self.model.Items[indexPath.item]; HomeSubItemModel * smodel = [HomeSubItemModel modelWithDictionary:dict]; [cell setData:smodel]; return cell; } - (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath { NSDictionary * dict = self.model.Items[indexPath.item]; HomeSubItemModel * model = [HomeSubItemModel modelWithDictionary:dict]; [collectionView deselectItemAtIndexPath:indexPath animated:YES]; if (self.ClickItemBlock) { self.ClickItemBlock(model); } } - (void)setShowBgColor { CAGradientLayer *gl = [CAGradientLayer layer]; NSArray *colors = [NSArray arrayWithObjects: (id)[[UIColor colorWithRed:255 green:255 blue:255 alpha:0] CGColor], //clearColor,透明度为0(显示为黑色,就像黑洞...) (id)[[UIColor colorWithRed:255 green:255 blue:255 alpha:0.5] CGColor],//clearColor,透明度为0.5 (id)[[UIColor colorWithRed:255 green:255 blue:255 alpha:1] CGColor], //clearColor,透明度为1(显示为透明) nil]; [gl setColors:colors]; [gl setStartPoint:CGPointMake(0.0f, 0.0f)]; [gl setEndPoint:CGPointMake(0.0f, 0.4f)]; [gl setFrame:CGRectMake(0, 0, SCREEN_WIDTH, 140)]; [[self.ShowView layer] setMask:gl]; } @end