YOUPAIHRMedalView.m 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. //
  2. // YOUPAIHRMedalView.m
  3. // VQU
  4. //
  5. // Created by 肖浩然的mac on 2021/9/24.
  6. // Copyright © 2021 MS. All rights reserved.
  7. //
  8. #import "YOUPAIHRMedalView.h"
  9. @interface YOUPAIHRMedalView ()<UICollectionViewDelegate, UICollectionViewDelegateFlowLayout, UICollectionViewDataSource>
  10. @property (nonatomic, strong) UICollectionView *youpaipcollectionView;
  11. @end
  12. @implementation YOUPAIHRMedalView
  13. -(instancetype)initWithFrame:(CGRect)frame{
  14. if (self = [super initWithFrame:frame]) {
  15. [self youpaifsetSubView];
  16. }
  17. return self;
  18. }
  19. -(void)youpaifsetSubView{
  20. UICollectionViewFlowLayout *flowLayout = [[UICollectionViewFlowLayout alloc] init];
  21. flowLayout.scrollDirection = UICollectionViewScrollDirectionVertical;
  22. UICollectionView *collectionView = [[UICollectionView alloc] initWithFrame:CGRectZero collectionViewLayout:flowLayout];
  23. self.youpaipcollectionView = collectionView;
  24. [self addSubview:collectionView];
  25. [self.youpaipcollectionView mas_makeConstraints:^(MASConstraintMaker *make) {
  26. make.top.mas_equalTo(0);
  27. make.left.mas_offset(0);
  28. make.right.mas_offset(0);
  29. make.bottom.mas_offset(0);
  30. }];
  31. self.youpaipcollectionView.backgroundColor = LCBkgColor;
  32. self.youpaipcollectionView.showsVerticalScrollIndicator = NO;
  33. self.youpaipcollectionView.showsHorizontalScrollIndicator = NO;
  34. self.youpaipcollectionView.bounces = NO;
  35. [self.youpaipcollectionView registerClass:[UICollectionViewCell class] forCellWithReuseIdentifier:@"HRMedalViewCell"];
  36. self.youpaipcollectionView.delegate = self;
  37. self.youpaipcollectionView.dataSource = self;
  38. }
  39. -(void)setYoupaipinfoModel:(YOUPAILCBaseInfo *)infoModel{
  40. _youpaipinfoModel = infoModel;
  41. [self.youpaipcollectionView reloadData];
  42. }
  43. #pragma mark <UICollectionViewDataSource>
  44. /**
  45. 返回区数
  46. @param collectionView 集合视图
  47. @return 返回区数
  48. */
  49. - (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView {
  50. return 1;
  51. }
  52. /**
  53. 返回项目数
  54. @param collectionView 集合视图
  55. @param section 区
  56. @return 项目数
  57. */
  58. - (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
  59. return self.youpaipinfoModel.youpaipbadge_all.count;
  60. }
  61. -(UICollectionViewCell*)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
  62. UICollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"HRMedalViewCell" forIndexPath:indexPath];
  63. cell.backgroundColor = LCBkgColor;
  64. //图片
  65. UIImageView *imageView = [UIImageView new];
  66. [cell addSubview:imageView];
  67. [imageView mas_makeConstraints:^(MASConstraintMaker *make) {
  68. make.left.mas_equalTo(0);
  69. make.right.mas_equalTo(0);
  70. make.top.mas_equalTo(0);
  71. make.bottom.mas_equalTo(0);
  72. }];
  73. YOUPAILZVipCarModel *model = self.youpaipinfoModel.youpaipbadge_all[indexPath.item];
  74. [imageView sd_setImageWithURL:[LCTools getImageUrlWithAddress:model.youpaipfile] placeholderImage:nil];
  75. imageView.contentMode = UIViewContentModeScaleAspectFill;
  76. imageView.clipsToBounds = YES;
  77. return cell;
  78. }
  79. #pragma mark UICollectionViewDelegateFlowLayout
  80. /**
  81. 项目大小
  82. @param collectionView 集合视图
  83. @param collectionViewLayout 布局
  84. @param indexPath 布局
  85. @return 大小
  86. */
  87. - (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath {
  88. YOUPAILZVipCarModel *model = self.youpaipinfoModel.youpaipbadge_all[indexPath.item];
  89. CGFloat width = [model.youpaipwidth floatValue];
  90. return CGSizeMake(width, 15);
  91. }
  92. #pragma mark - X间距
  93. - (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout minimumInteritemSpacingForSectionAtIndex:(NSInteger)section {
  94. return 2.0;
  95. }
  96. //设置段落的内边距
  97. - (UIEdgeInsets)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout insetForSectionAtIndex:(NSInteger)section
  98. {
  99. return UIEdgeInsetsMake(0,0,0,0);//UIEdgeInsetsMake(CGFloat top, CGFloat left, CGFloat bottom, CGFloat right)
  100. }
  101. @end