HomeUserPrivilegeCell.m 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. //
  2. // HomeUserPrivilegeCell.m
  3. // smartRhino
  4. //
  5. // Created by niuzhen on 2020/5/16.
  6. // Copyright © 2020 tederen. All rights reserved.
  7. //
  8. #import "HomeUserPrivilegeCell.h"
  9. #import "BookHomeSubCell.h"
  10. #import "BookHomeSubModel.h"
  11. @implementation HomeUserPrivilegeCell
  12. - (void)awakeFromNib {
  13. [super awakeFromNib];
  14. self.lookBtn.layer.cornerRadius = 10.f;
  15. self.lookBtn.layer.borderWidth = 0.5f;
  16. self.lookBtn.layer.borderColor = UIColorHex(0xE0E0E0).CGColor;
  17. self.lookBtn.layer.masksToBounds = YES;
  18. self.collectionView.delegate = self;
  19. self.collectionView.dataSource = self;
  20. self.collectionView.showsVerticalScrollIndicator = NO;
  21. self.collectionView.showsHorizontalScrollIndicator = NO;
  22. [self.collectionView registerNib:[UINib nibWithNibName:@"BookHomeSubCell" bundle:nil] forCellWithReuseIdentifier:@"BookHomeSubCell"];
  23. }
  24. - (void)setSelected:(BOOL)selected animated:(BOOL)animated {
  25. [super setSelected:selected animated:animated];
  26. }
  27. + (HomeUserPrivilegeCell *)configCell:(UITableView *)tableView indexPath:(NSIndexPath *)indexPath{
  28. static NSString *cellIdentifer = @"HomeUserPrivilegeCell";
  29. HomeUserPrivilegeCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifer];
  30. if (cell == nil) {
  31. cell = [[[NSBundle mainBundle] loadNibNamed:@"HomeUserPrivilegeCell" owner:nil options:nil] objectAtIndex:0];
  32. }
  33. return cell;
  34. }
  35. - (void)setDataWithItem:(NSInteger)Item isUnUser:(BOOL)isUser model:(HomeSubModel *)model
  36. {
  37. self.model = model;
  38. self.TitleL.text = model.LabelName;
  39. self.collectH.constant = 109.f * model.Items.count;
  40. [self.contentView setBackgroundColor:Item % 2 == 0 ? UIColorHex(0xFFFFFF) : UIColorHex(0xF7F7F9)];
  41. [self.collectionView setBackgroundColor:Item % 2 == 0 ? UIColorHex(0xFFFFFF) : UIColorHex(0xF7F7F9)];
  42. UICollectionViewFlowLayout * layout = [[UICollectionViewFlowLayout alloc]init];
  43. [self.collectionView setContentSize:CGSizeMake(SCREEN_WIDTH, 109 * model.Items.count)];
  44. layout.sectionInset = UIEdgeInsetsMake(0, 0, 0, 0);
  45. [self.collectionView setCollectionViewLayout:layout];
  46. [self.collectionView setContentOffset:CGPointZero animated:NO];
  47. [self.collectionView reloadData];
  48. self.ShowView.hidden = !isUser;
  49. if (isUser) {
  50. [self setShowBgColor];
  51. }
  52. [self.collectionView reloadData];
  53. }
  54. - (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout minimumLineSpacingForSectionAtIndex:(NSInteger)section
  55. {
  56. return 0.f;
  57. }
  58. - (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout minimumInteritemSpacingForSectionAtIndex:(NSInteger)section
  59. {
  60. return 0.f;
  61. }
  62. - (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
  63. {
  64. return self.model.Items.count;
  65. }
  66. - (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView
  67. {
  68. return 1;
  69. }
  70. -(CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath
  71. {
  72. return CGSizeMake(SCREEN_WIDTH, 109);
  73. }
  74. - (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
  75. {
  76. BookHomeSubCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"BookHomeSubCell" forIndexPath:indexPath];
  77. NSDictionary * dict = self.model.Items[indexPath.item];
  78. HomeSubItemModel * smodel = [HomeSubItemModel modelWithDictionary:dict];
  79. [cell setData:smodel];
  80. return cell;
  81. }
  82. - (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
  83. {
  84. NSDictionary * dict = self.model.Items[indexPath.item];
  85. HomeSubItemModel * model = [HomeSubItemModel modelWithDictionary:dict];
  86. [collectionView deselectItemAtIndexPath:indexPath animated:YES];
  87. if (self.ClickItemBlock) {
  88. self.ClickItemBlock(model);
  89. }
  90. }
  91. - (void)setShowBgColor
  92. {
  93. CAGradientLayer *gl = [CAGradientLayer layer];
  94. NSArray *colors = [NSArray arrayWithObjects:
  95. (id)[[UIColor colorWithRed:255 green:255 blue:255 alpha:0] CGColor], //clearColor,透明度为0(显示为黑色,就像黑洞...)
  96. (id)[[UIColor colorWithRed:255 green:255 blue:255 alpha:0.5] CGColor],//clearColor,透明度为0.5
  97. (id)[[UIColor colorWithRed:255 green:255 blue:255 alpha:1] CGColor], //clearColor,透明度为1(显示为透明)
  98. nil];
  99. [gl setColors:colors];
  100. [gl setStartPoint:CGPointMake(0.0f, 0.0f)];
  101. [gl setEndPoint:CGPointMake(0.0f, 0.4f)];
  102. [gl setFrame:CGRectMake(0, 0, SCREEN_WIDTH, 140)];
  103. [[self.ShowView layer] setMask:gl];
  104. }
  105. @end