YOUPAIZYUserZiLiaoDTCell.m 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196
  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 "YOUPAIZYUserZiLiaoDTCell.h"
  9. #import "YOUPAIZYUserZiLiaoDTPhotoCell.h"
  10. #import "YOUPAILCDynamicArrayModel.h"
  11. @interface YOUPAIZYUserZiLiaoDTCell()<UICollectionViewDelegate, UICollectionViewDelegateFlowLayout, UICollectionViewDataSource>
  12. @property (nonatomic, strong) UICollectionView *youpaipcollectionView;
  13. @end
  14. @implementation YOUPAIZYUserZiLiaoDTCell
  15. -(instancetype)initWithFrame:(CGRect)frame{
  16. if (self = [super initWithFrame:frame]) {
  17. [self youpaifsetSubView];
  18. }
  19. return self;
  20. }
  21. -(void)youpaifsetSubView{
  22. UIView *titleView = [UIView new];
  23. [self.contentView addSubview:titleView];
  24. [titleView mas_makeConstraints:^(MASConstraintMaker *make) {
  25. make.left.mas_equalTo(0);
  26. make.right.mas_equalTo(0);
  27. make.top.mas_equalTo(0);
  28. make.height.mas_equalTo(17);
  29. }];
  30. titleView.backgroundColor = [UIColor whiteColor];
  31. self.youpaiptitleLabel = [[UILabel alloc] init];
  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. //arrow
  39. UIButton *arrowBtn = [UIButton new];
  40. [self.contentView addSubview:arrowBtn];
  41. [arrowBtn mas_makeConstraints:^(MASConstraintMaker *make) {
  42. make.width.mas_equalTo(70);
  43. make.centerY.mas_equalTo(self.youpaiptitleLabel);
  44. make.right.mas_equalTo(-6);
  45. }];
  46. [arrowBtn setSemanticContentAttribute:UISemanticContentAttributeForceRightToLeft];
  47. [arrowBtn setImage:[UIImage imageNamed:@"vqu_images_zhuye_ZL_arrow"]
  48. forState:UIControlStateNormal];
  49. [arrowBtn addTarget:self action:@selector(youpaifarrowBtnClick) forControlEvents:UIControlEventTouchUpInside];
  50. [arrowBtn setTitle:@"查看全部" forState:UIControlStateNormal];
  51. arrowBtn.titleLabel.font = [UIFont systemFontOfSize:10];
  52. [arrowBtn setTitleColor:HexColorFromRGB(0xA3AABE) forState:UIControlStateNormal];
  53. UICollectionViewFlowLayout *flowLayout = [[UICollectionViewFlowLayout alloc] init];
  54. flowLayout.scrollDirection = UICollectionViewScrollDirectionVertical;
  55. self.youpaipcollectionView = [[UICollectionView alloc] initWithFrame:CGRectZero collectionViewLayout:flowLayout];
  56. [self.contentView addSubview:self.youpaipcollectionView];
  57. [self.youpaipcollectionView mas_makeConstraints:^(MASConstraintMaker *make) {
  58. make.top.mas_equalTo(titleView.mas_bottom).offset(9);
  59. make.left.mas_offset(12.f);
  60. make.right.mas_offset(0);
  61. make.bottom.mas_offset(0.f);
  62. }];
  63. self.youpaipcollectionView.userInteractionEnabled = NO;
  64. self.youpaipcollectionView.backgroundColor = [UIColor whiteColor];
  65. self.youpaipcollectionView.showsVerticalScrollIndicator = NO;
  66. self.youpaipcollectionView.showsHorizontalScrollIndicator = NO;
  67. self.youpaipcollectionView.bounces = NO;
  68. [self.youpaipcollectionView registerClass:[YOUPAIZYUserZiLiaoDTPhotoCell class] forCellWithReuseIdentifier:NSStringFromClass([YOUPAIZYUserZiLiaoDTPhotoCell class])];
  69. self.youpaipcollectionView.delegate = self;
  70. self.youpaipcollectionView.dataSource = self;
  71. }
  72. -(void)setYoupaipalbumArray:(NSArray *)albumArray{
  73. _youpaipalbumArray = albumArray;
  74. if (albumArray.count>0) {
  75. NSInteger count = 0;
  76. if (albumArray.count>=5) {
  77. count = 5;
  78. }else{
  79. count =albumArray.count;
  80. }
  81. NSMutableArray *arr = [NSMutableArray new];
  82. for (int i = 0; i<count; i++) {
  83. [arr addObject:albumArray[i]];
  84. }
  85. _youpaipalbumArray = arr;
  86. }
  87. CGFloat width = self.youpaipalbumArray.count*63+(self.youpaipalbumArray.count-1)*9;
  88. [self.youpaipcollectionView mas_updateConstraints:^(MASConstraintMaker *make) {
  89. make.width.mas_offset(width);
  90. }];
  91. }
  92. #pragma mark <UICollectionViewDataSource>
  93. /**
  94. 返回区数
  95. @param collectionView 集合视图
  96. @return 返回区数
  97. */
  98. - (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView {
  99. return 1;
  100. }
  101. /**
  102. 返回项目数
  103. @param collectionView 集合视图
  104. @param section 区
  105. @return 项目数
  106. */
  107. - (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
  108. return self.youpaipalbumArray.count;
  109. }
  110. -(UICollectionViewCell*)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
  111. // NSString *imageUrl = self.albumArray[indexPath.item];
  112. YOUPAIZYUserZiLiaoDTPhotoCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:NSStringFromClass([YOUPAIZYUserZiLiaoDTPhotoCell class]) forIndexPath:indexPath];
  113. YOUPAILCDynamicArrayModel *model = self.youpaipalbumArray[indexPath.item];
  114. if (model.youpaiptype == 1) {//视频
  115. cell.youpaipplayImageView.hidden = NO;
  116. [cell.youpaipiconImageView sd_setImageWithURL:[NSURL URLWithString:model.youpaipurl] placeholderImage:nil];
  117. }else{
  118. cell.youpaipplayImageView.hidden = YES;
  119. [cell.youpaipiconImageView sd_setImageWithURL:[LCTools getImageUrlWithAddress:model.youpaipurl] placeholderImage:nil];
  120. }
  121. return cell;
  122. }
  123. -(void)youpaifarrowBtnClick{
  124. if ([self.youpaipdelegate respondsToSelector:@selector(youpaifDTDidCellOrBtnclick)]) {
  125. [self.youpaipdelegate youpaifDTDidCellOrBtnclick];
  126. }
  127. }
  128. -(void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath{
  129. if ([self.youpaipdelegate respondsToSelector:@selector(youpaifDTDidCellOrBtnclick)]) {
  130. [self.youpaipdelegate youpaifDTDidCellOrBtnclick];
  131. }
  132. }
  133. #pragma mark UICollectionViewDelegateFlowLayout
  134. /**
  135. 项目大小
  136. @param collectionView 集合视图
  137. @param collectionViewLayout 布局
  138. @param indexPath 布局
  139. @return 大小
  140. */
  141. - (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath {
  142. return CGSizeMake(63, 63);
  143. }
  144. #pragma mark - X间距
  145. - (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout minimumInteritemSpacingForSectionAtIndex:(NSInteger)section {
  146. return 2.0;
  147. }
  148. //设置段落的内边距
  149. - (UIEdgeInsets)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout insetForSectionAtIndex:(NSInteger)section
  150. {
  151. return UIEdgeInsetsMake(0,0,0,0);//UIEdgeInsetsMake(CGFloat top, CGFloat left, CGFloat bottom, CGFloat right)
  152. }
  153. @end