HomeUserPrivilegeCell.m 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  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
  36. {
  37. self.collectH.constant = 109.f * 3;
  38. [self.contentView setBackgroundColor:Item % 2 == 0 ? UIColorHex(0xFFFFFF) : UIColorHex(0xF7F7F9)];
  39. [self.collectionView setBackgroundColor:Item % 2 == 0 ? UIColorHex(0xFFFFFF) : UIColorHex(0xF7F7F9)];
  40. UICollectionViewFlowLayout * layout = [[UICollectionViewFlowLayout alloc]init];
  41. [self.collectionView setContentSize:CGSizeMake(SCREEN_WIDTH, 109 * 3)];
  42. layout.sectionInset = UIEdgeInsetsMake(0, 0, 0, 0);
  43. [self.collectionView setCollectionViewLayout:layout];
  44. [self.collectionView setContentOffset:CGPointZero animated:NO];
  45. [self.collectionView reloadData];
  46. self.ShowView.hidden = !isUser;
  47. if (isUser) {
  48. [self setShowBgColor];
  49. }
  50. WS(weakSelf);
  51. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.2 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
  52. [weakSelf.collectionView reloadData];
  53. });
  54. }
  55. - (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout minimumLineSpacingForSectionAtIndex:(NSInteger)section
  56. {
  57. return 0.f;
  58. }
  59. - (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout minimumInteritemSpacingForSectionAtIndex:(NSInteger)section
  60. {
  61. return 0.f;
  62. }
  63. - (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
  64. {
  65. return 3;
  66. }
  67. - (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView
  68. {
  69. return 1;
  70. }
  71. -(CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath
  72. {
  73. return CGSizeMake(SCREEN_WIDTH, 109);
  74. }
  75. - (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
  76. {
  77. BookHomeSubCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"BookHomeSubCell" forIndexPath:indexPath];
  78. [cell setData];
  79. return cell;
  80. }
  81. - (void)setShowBgColor
  82. {
  83. CAGradientLayer *gl = [CAGradientLayer layer];
  84. NSArray *colors = [NSArray arrayWithObjects:
  85. (id)[[UIColor colorWithRed:255 green:255 blue:255 alpha:0] CGColor], //clearColor,透明度为0(显示为黑色,就像黑洞...)
  86. (id)[[UIColor colorWithRed:255 green:255 blue:255 alpha:0.5] CGColor],//clearColor,透明度为0.5
  87. (id)[[UIColor colorWithRed:255 green:255 blue:255 alpha:1] CGColor], //clearColor,透明度为1(显示为透明)
  88. nil];
  89. [gl setColors:colors];
  90. [gl setStartPoint:CGPointMake(0.0f, 0.0f)];
  91. [gl setEndPoint:CGPointMake(0.0f, 0.4f)];
  92. [gl setFrame:CGRectMake(0, 0, SCREEN_WIDTH, 140)];
  93. [[self.ShowView layer] setMask:gl];
  94. }
  95. @end