YOUPAIZYUserZiLiaoLWCell.m 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  1. //
  2. // YOUPAIZYUserZiLiaoDTCell.m
  3. // VQU
  4. //
  5. // Created by 肖浩然的mac on 2021/7/10.
  6. // Copyright © 2021 leo. All rights reserved.
  7. //
  8. #import "YOUPAIZYUserZiLiaoLWCell.h"
  9. #import "YOUPAIZYUserZiLiaoBHPhotoCell.h"
  10. @interface YOUPAIZYUserZiLiaoLWCell()<UICollectionViewDelegate, UICollectionViewDelegateFlowLayout, UICollectionViewDataSource>
  11. @property (nonatomic, strong) UICollectionView *youpaipcollectionView;
  12. @end
  13. @implementation YOUPAIZYUserZiLiaoLWCell
  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 = LCWhiteColor;
  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. self.youpaiptitleLabel.textColor = [UIColor whiteColor];
  38. UICollectionViewFlowLayout *flowLayout = [[UICollectionViewFlowLayout alloc] init];
  39. flowLayout.scrollDirection = UICollectionViewScrollDirectionVertical;
  40. self.youpaipcollectionView = [[UICollectionView alloc] initWithFrame:CGRectZero collectionViewLayout:flowLayout];
  41. [self.contentView addSubview:self.youpaipcollectionView];
  42. [self.youpaipcollectionView mas_makeConstraints:^(MASConstraintMaker *make) {
  43. make.top.mas_equalTo(titleView.mas_bottom);
  44. make.left.mas_offset(12.f);
  45. make.right.mas_offset(-12.f);
  46. make.bottom.mas_offset(0.f);
  47. }];
  48. self.youpaipcollectionView.userInteractionEnabled = NO;
  49. self.youpaipcollectionView.backgroundColor = LCWhiteColor;
  50. self.youpaipcollectionView.showsVerticalScrollIndicator = NO;
  51. self.youpaipcollectionView.showsHorizontalScrollIndicator = NO;
  52. self.youpaipcollectionView.bounces = NO;
  53. //arrow
  54. UIButton *arrowBtn = [UIButton new];
  55. [self.contentView addSubview:arrowBtn];
  56. [arrowBtn mas_makeConstraints:^(MASConstraintMaker *make) {
  57. make.size.mas_equalTo(CGSizeMake(10, 10));
  58. make.centerY.mas_equalTo(self.youpaiptitleLabel);
  59. make.right.mas_equalTo(-6);
  60. }];
  61. [arrowBtn setImage:[UIImage imageNamed:@"vqu_images_zhuye_ZL_arrow"]
  62. forState:UIControlStateNormal];
  63. arrowBtn.titleLabel.font = [UIFont systemFontOfSize:10];
  64. [arrowBtn setTitleColor:HexColorFromRGB(0xA3AABE) forState:UIControlStateNormal];
  65. [self.youpaipcollectionView registerClass:[YOUPAIZYUserZiLiaoBHPhotoCell class] forCellWithReuseIdentifier:NSStringFromClass([YOUPAIZYUserZiLiaoBHPhotoCell class])];
  66. self.youpaipcollectionView.delegate = self;
  67. self.youpaipcollectionView.dataSource = self;
  68. }
  69. -(void)setYoupaipdataArr:(NSArray *)dataArr{
  70. _youpaipdataArr = dataArr;
  71. if (dataArr.count>0) {
  72. NSInteger count = 0;
  73. if (dataArr.count>=5) {
  74. count = 5;
  75. }else {
  76. count =dataArr.count;
  77. }
  78. NSMutableArray *arr = [NSMutableArray new];
  79. for (int i = 0; i<count; i++) {
  80. [arr addObject:dataArr[i]];
  81. }
  82. _youpaipdataArr = arr;
  83. }
  84. }
  85. -(void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath{
  86. if ([self.youpaipdelegate respondsToSelector:@selector(youpaifLWDidCellOrBtnclick)]) {
  87. [self.youpaipdelegate youpaifLWDidCellOrBtnclick];
  88. }
  89. }
  90. #pragma mark <UICollectionViewDataSource>
  91. /**
  92. 返回区数
  93. @param collectionView 集合视图
  94. @return 返回区数
  95. */
  96. - (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView {
  97. return 1;
  98. }
  99. /**
  100. 返回项目数
  101. @param collectionView 集合视图
  102. @param section 区
  103. @return 项目数
  104. */
  105. - (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
  106. return self.youpaipdataArr.count;
  107. }
  108. -(UICollectionViewCell*)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
  109. YOUPAIZYUserZiLiaoBHPhotoCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:NSStringFromClass([YOUPAIZYUserZiLiaoBHPhotoCell class]) forIndexPath:indexPath];
  110. YOUPAILCGiftModel *model = self.youpaipdataArr[indexPath.item];
  111. cell.backgroundColor = LCWhiteColor;
  112. NSString *imageUrl = [NSString stringWithFormat:@"%@/%@",[LCSaveData getImageUrl]?[LCSaveData getImageUrl]:BaseImgUrl,model.youpaipimg];
  113. [cell.youpaipiconImageView sd_setImageWithURL:[NSURL URLWithString:imageUrl] placeholderImage:nil];
  114. cell.youpaipNumLabel.text = [NSString stringWithFormat:@"x%ld",(long)model.youpaiptotal];
  115. cell.youpaipNameLabel.text = model.youpaipname;
  116. return cell;
  117. }
  118. #pragma mark UICollectionViewDelegateFlowLayout
  119. /**
  120. 项目大小
  121. @param collectionView 集合视图
  122. @param collectionViewLayout 布局
  123. @param indexPath 布局
  124. @return 大小
  125. */
  126. - (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath {
  127. return CGSizeMake(63, 95+9+17+30);
  128. }
  129. #pragma mark - X间距
  130. - (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout minimumInteritemSpacingForSectionAtIndex:(NSInteger)section {
  131. return 9.0;
  132. }
  133. //设置段落的内边距
  134. - (UIEdgeInsets)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout insetForSectionAtIndex:(NSInteger)section
  135. {
  136. return UIEdgeInsetsMake(0,0,0,0);//UIEdgeInsetsMake(CGFloat top, CGFloat left, CGFloat bottom, CGFloat right)
  137. }
  138. @end