123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129 |
- //
- // YOUPAIHRMedalView.m
- // VQU
- //
- // Created by 肖浩然的mac on 2021/9/24.
- // Copyright © 2021 MS. All rights reserved.
- //
- #import "YOUPAIHRMedalView.h"
- @interface YOUPAIHRMedalView ()<UICollectionViewDelegate, UICollectionViewDelegateFlowLayout, UICollectionViewDataSource>
- @property (nonatomic, strong) UICollectionView *youpaipcollectionView;
- @end
- @implementation YOUPAIHRMedalView
- -(instancetype)initWithFrame:(CGRect)frame{
- if (self = [super initWithFrame:frame]) {
- [self youpaifsetSubView];
- }
- return self;
- }
- -(void)youpaifsetSubView{
-
- UICollectionViewFlowLayout *flowLayout = [[UICollectionViewFlowLayout alloc] init];
- flowLayout.scrollDirection = UICollectionViewScrollDirectionVertical;
- UICollectionView *collectionView = [[UICollectionView alloc] initWithFrame:CGRectZero collectionViewLayout:flowLayout];
- self.youpaipcollectionView = collectionView;
- [self addSubview:collectionView];
- [self.youpaipcollectionView mas_makeConstraints:^(MASConstraintMaker *make) {
- make.top.mas_equalTo(0);
- make.left.mas_offset(0);
- make.right.mas_offset(0);
- make.bottom.mas_offset(0);
- }];
-
- self.youpaipcollectionView.backgroundColor = LCBkgColor;
- self.youpaipcollectionView.showsVerticalScrollIndicator = NO;
- self.youpaipcollectionView.showsHorizontalScrollIndicator = NO;
- self.youpaipcollectionView.bounces = NO;
- [self.youpaipcollectionView registerClass:[UICollectionViewCell class] forCellWithReuseIdentifier:@"HRMedalViewCell"];
- self.youpaipcollectionView.delegate = self;
- self.youpaipcollectionView.dataSource = self;
-
-
-
- }
- -(void)setYoupaipinfoModel:(YOUPAILCBaseInfo *)infoModel{
-
- _youpaipinfoModel = infoModel;
- [self.youpaipcollectionView reloadData];
- }
- #pragma mark <UICollectionViewDataSource>
- /**
- 返回区数
-
- @param collectionView 集合视图
- @return 返回区数
- */
- - (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView {
- return 1;
- }
- /**
- 返回项目数
-
- @param collectionView 集合视图
- @param section 区
- @return 项目数
- */
- - (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
- return self.youpaipinfoModel.youpaipbadge_all.count;
- }
- -(UICollectionViewCell*)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
-
- UICollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"HRMedalViewCell" forIndexPath:indexPath];
- cell.backgroundColor = LCBkgColor;
- //图片
- UIImageView *imageView = [UIImageView new];
- [cell addSubview:imageView];
- [imageView mas_makeConstraints:^(MASConstraintMaker *make) {
- make.left.mas_equalTo(0);
- make.right.mas_equalTo(0);
- make.top.mas_equalTo(0);
- make.bottom.mas_equalTo(0);
- }];
- YOUPAILZVipCarModel *model = self.youpaipinfoModel.youpaipbadge_all[indexPath.item];
- [imageView sd_setImageWithURL:[LCTools getImageUrlWithAddress:model.youpaipfile] placeholderImage:nil];
- imageView.contentMode = UIViewContentModeScaleAspectFill;
- imageView.clipsToBounds = YES;
- return cell;
- }
- #pragma mark UICollectionViewDelegateFlowLayout
- /**
- 项目大小
-
- @param collectionView 集合视图
- @param collectionViewLayout 布局
- @param indexPath 布局
- @return 大小
- */
- - (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath {
- YOUPAILZVipCarModel *model = self.youpaipinfoModel.youpaipbadge_all[indexPath.item];
- CGFloat width = [model.youpaipwidth floatValue];
- return CGSizeMake(width, 15);
- }
- #pragma mark - X间距
- - (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout minimumInteritemSpacingForSectionAtIndex:(NSInteger)section {
- return 2.0;
- }
- //设置段落的内边距
- - (UIEdgeInsets)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout insetForSectionAtIndex:(NSInteger)section
- {
- return UIEdgeInsetsMake(0,0,0,0);//UIEdgeInsetsMake(CGFloat top, CGFloat left, CGFloat bottom, CGFloat right)
- }
- @end
|