YOUPAIZYUserZiLiaoXZCell.m 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200
  1. //
  2. // YOUPAIZYUserZiLiaoXZCell.m
  3. // VQU
  4. //
  5. // Created by 肖浩然的mac on 2021/9/7.
  6. // Copyright © 2021 MS. All rights reserved.
  7. //
  8. #import "YOUPAIZYUserZiLiaoXZCell.h"
  9. #import "YOUPAIZYUserZiLiaoBHPhotoCell.h"
  10. @interface YOUPAIZYUserZiLiaoXZCell()<UICollectionViewDelegate, UICollectionViewDelegateFlowLayout, UICollectionViewDataSource>
  11. @property (nonatomic, strong) UICollectionView *youpaipcollectionView;
  12. @end
  13. @implementation YOUPAIZYUserZiLiaoXZCell
  14. -(instancetype)initWithFrame:(CGRect)frame{
  15. if (self = [super initWithFrame:frame]) {
  16. [self youpaifsetSubView];
  17. }
  18. return self;
  19. }
  20. -(void)youpaifsetSubView{
  21. UIView *titleView = [UIView new];
  22. [self.contentView addSubview:titleView];
  23. [titleView mas_makeConstraints:^(MASConstraintMaker *make) {
  24. make.left.mas_equalTo(0);
  25. make.right.mas_equalTo(0);
  26. make.top.mas_equalTo(0);
  27. make.height.mas_equalTo(43);
  28. }];
  29. titleView.backgroundColor = LCBkgColor;
  30. self.youpaiptitleLabel = [[UILabel alloc] init];
  31. self.youpaiptitleLabel.font = LCBoldFont(14);
  32. [titleView addSubview:self.youpaiptitleLabel];
  33. [self.youpaiptitleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
  34. make.centerY.mas_equalTo(0);
  35. make.left.mas_equalTo(14);
  36. }];
  37. UICollectionViewFlowLayout *flowLayout = [[UICollectionViewFlowLayout alloc] init];
  38. flowLayout.scrollDirection = UICollectionViewScrollDirectionVertical;
  39. self.youpaipcollectionView = [[UICollectionView alloc] initWithFrame:CGRectZero collectionViewLayout:flowLayout];
  40. [self.contentView addSubview:self.youpaipcollectionView];
  41. [self.youpaipcollectionView mas_makeConstraints:^(MASConstraintMaker *make) {
  42. make.top.mas_equalTo(titleView.mas_bottom);
  43. make.left.mas_offset(14.f);
  44. make.right.mas_offset(-44.f);
  45. make.bottom.mas_offset(0.f);
  46. }];
  47. self.youpaipcollectionView.backgroundColor = LCBkgColor;
  48. self.youpaipcollectionView.showsVerticalScrollIndicator = NO;
  49. self.youpaipcollectionView.showsHorizontalScrollIndicator = NO;
  50. self.youpaipcollectionView.bounces = NO;
  51. //arrow
  52. UIButton *arrowBtn = [UIButton new];
  53. [self.contentView addSubview:arrowBtn];
  54. [arrowBtn mas_makeConstraints:^(MASConstraintMaker *make) {
  55. make.left.mas_equalTo(self.youpaipcollectionView.mas_right);
  56. make.top.mas_equalTo(self.youpaipcollectionView);
  57. make.bottom.mas_equalTo(self.youpaipcollectionView);
  58. make.right.mas_equalTo(0);
  59. }];
  60. [arrowBtn setImage:[UIImage imageNamed:@"vqu_images_H_cell_arrow_gray"] forState:UIControlStateNormal];
  61. [arrowBtn addTarget:self action:@selector(youpaifarrowBtnClick) forControlEvents:UIControlEventTouchUpInside];
  62. [self.youpaipcollectionView registerClass:[YOUPAIZYUserZiLiaoBHPhotoCell class] forCellWithReuseIdentifier:NSStringFromClass([YOUPAIZYUserZiLiaoBHPhotoCell class])];
  63. self.youpaipcollectionView.delegate = self;
  64. self.youpaipcollectionView.dataSource = self;
  65. //分割线
  66. UIView *viewLine =[UIView new];
  67. [self addSubview:viewLine];
  68. [viewLine mas_makeConstraints:^(MASConstraintMaker *make) {
  69. make.left.mas_equalTo(14);
  70. make.right.mas_equalTo(-14);
  71. make.bottom.mas_equalTo(0);
  72. make.height.mas_equalTo(0.5f);
  73. }];
  74. viewLine.backgroundColor =HexColorFromRGB(0x28262D);
  75. }
  76. -(void)setYoupaipdataArr:(NSArray *)dataArr{
  77. _youpaipdataArr = dataArr;
  78. self.youpaiptitleLabel.attributedText = [LCTools setRichTextWithTitle:@"已收藏" subTitle:[NSString stringWithFormat:@"(%lu人)",(unsigned long)self.youpaipdataArr.count] titleColor:[UIColor whiteColor] subTitleColor:HexColorFromRGB(0x9F9DA5) titleFontSize:14 subTitleFontSize:12];
  79. if (dataArr.count>0) {
  80. int count = 0;
  81. if(dataArr.count >= 5){
  82. count = 5;
  83. }else if(dataArr.count == 4){
  84. count = 4;
  85. }else if(dataArr.count == 3){
  86. count = 3;
  87. }else if(dataArr.count == 2){
  88. count = 2;
  89. }
  90. else {
  91. count = 1;
  92. }
  93. NSMutableArray *arr = [NSMutableArray new];
  94. for (int i = 0; i<count; i++) {
  95. [arr addObject:dataArr[i]];
  96. }
  97. _youpaipdataArr = arr;
  98. }
  99. }
  100. -(void)youpaifarrowBtnClick{
  101. // if ([self.delegate respondsToSelector:@selector(youpaifSHDidCellOrBtnclick:)]) {
  102. // [self.delegate youpaifSHDidCellOrBtnclick:NO];
  103. // }
  104. }
  105. -(void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath{
  106. // if (indexPath.item == self.dataArr.count) {
  107. // if ([self.delegate respondsToSelector:@selector(youpaifSHDidCellOrBtnclick:)]) {
  108. // [self.delegate youpaifSHDidCellOrBtnclick:YES];
  109. // }
  110. // }else{
  111. // if ([self.delegate respondsToSelector:@selector(youpaifSHDidCellOrBtnclick:)]) {
  112. // [self.delegate youpaifSHDidCellOrBtnclick:NO];
  113. // }
  114. // }
  115. }
  116. #pragma mark <UICollectionViewDataSource>
  117. /**
  118. 返回区数
  119. @param collectionView 集合视图
  120. @return 返回区数
  121. */
  122. - (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView {
  123. return 1;
  124. }
  125. /**
  126. 返回项目数
  127. @param collectionView 集合视图
  128. @param section 区
  129. @return 项目数
  130. */
  131. - (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
  132. return self.youpaipdataArr.count+1;
  133. }
  134. -(UICollectionViewCell*)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
  135. YOUPAIZYUserZiLiaoBHPhotoCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:NSStringFromClass([YOUPAIZYUserZiLiaoBHPhotoCell class]) forIndexPath:indexPath];
  136. cell.backgroundColor = LCBkgColor;
  137. // if (indexPath.row == self.dataArr.count) {
  138. cell.youpaipiconImageView.image = [UIImage imageNamed:@"vqu_images_guard"];
  139. // }else{
  140. // NSString *imageUrl = self.dataArr[indexPath.item];
  141. // [cell.iconImageView sd_setImageWithURL:[NSURL URLWithString:imageUrl] placeholderImage:nil];
  142. //
  143. // }
  144. return cell;
  145. }
  146. #pragma mark UICollectionViewDelegateFlowLayout
  147. /**
  148. 项目大小
  149. @param collectionView 集合视图
  150. @param collectionViewLayout 布局
  151. @param indexPath 布局
  152. @return 大小
  153. */
  154. - (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath {
  155. return CGSizeMake(42, 42);
  156. }
  157. #pragma mark - X间距
  158. - (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout minimumInteritemSpacingForSectionAtIndex:(NSInteger)section {
  159. return 13.0;
  160. }
  161. //设置段落的内边距
  162. - (UIEdgeInsets)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout insetForSectionAtIndex:(NSInteger)section
  163. {
  164. return UIEdgeInsetsMake(0,0,0,0);//UIEdgeInsetsMake(CGFloat top, CGFloat left, CGFloat bottom, CGFloat right)
  165. }
  166. @end