123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200 |
- //
- // YOUPAIZYUserZiLiaoXZCell.m
- // VQU
- //
- // Created by 肖浩然的mac on 2021/9/7.
- // Copyright © 2021 MS. All rights reserved.
- //
- #import "YOUPAIZYUserZiLiaoXZCell.h"
- #import "YOUPAIZYUserZiLiaoBHPhotoCell.h"
- @interface YOUPAIZYUserZiLiaoXZCell()<UICollectionViewDelegate, UICollectionViewDelegateFlowLayout, UICollectionViewDataSource>
- @property (nonatomic, strong) UICollectionView *youpaipcollectionView;
- @end
- @implementation YOUPAIZYUserZiLiaoXZCell
- -(instancetype)initWithFrame:(CGRect)frame{
-
- if (self = [super initWithFrame:frame]) {
- [self youpaifsetSubView];
- }
- return self;
- }
- -(void)youpaifsetSubView{
-
- UIView *titleView = [UIView new];
- [self.contentView addSubview:titleView];
- [titleView mas_makeConstraints:^(MASConstraintMaker *make) {
- make.left.mas_equalTo(0);
- make.right.mas_equalTo(0);
- make.top.mas_equalTo(0);
- make.height.mas_equalTo(43);
- }];
- titleView.backgroundColor = LCBkgColor;
-
- self.youpaiptitleLabel = [[UILabel alloc] init];
- self.youpaiptitleLabel.font = LCBoldFont(14);
- [titleView addSubview:self.youpaiptitleLabel];
- [self.youpaiptitleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
- make.centerY.mas_equalTo(0);
- make.left.mas_equalTo(14);
-
- }];
-
- UICollectionViewFlowLayout *flowLayout = [[UICollectionViewFlowLayout alloc] init];
- flowLayout.scrollDirection = UICollectionViewScrollDirectionVertical;
- self.youpaipcollectionView = [[UICollectionView alloc] initWithFrame:CGRectZero collectionViewLayout:flowLayout];
- [self.contentView addSubview:self.youpaipcollectionView];
- [self.youpaipcollectionView mas_makeConstraints:^(MASConstraintMaker *make) {
- make.top.mas_equalTo(titleView.mas_bottom);
- make.left.mas_offset(14.f);
- make.right.mas_offset(-44.f);
- make.bottom.mas_offset(0.f);
- }];
-
- self.youpaipcollectionView.backgroundColor = LCBkgColor;
- self.youpaipcollectionView.showsVerticalScrollIndicator = NO;
- self.youpaipcollectionView.showsHorizontalScrollIndicator = NO;
- self.youpaipcollectionView.bounces = NO;
- //arrow
- UIButton *arrowBtn = [UIButton new];
- [self.contentView addSubview:arrowBtn];
- [arrowBtn mas_makeConstraints:^(MASConstraintMaker *make) {
- make.left.mas_equalTo(self.youpaipcollectionView.mas_right);
- make.top.mas_equalTo(self.youpaipcollectionView);
- make.bottom.mas_equalTo(self.youpaipcollectionView);
- make.right.mas_equalTo(0);
- }];
- [arrowBtn setImage:[UIImage imageNamed:@"vqu_images_H_cell_arrow_gray"] forState:UIControlStateNormal];
- [arrowBtn addTarget:self action:@selector(youpaifarrowBtnClick) forControlEvents:UIControlEventTouchUpInside];
- [self.youpaipcollectionView registerClass:[YOUPAIZYUserZiLiaoBHPhotoCell class] forCellWithReuseIdentifier:NSStringFromClass([YOUPAIZYUserZiLiaoBHPhotoCell class])];
-
- self.youpaipcollectionView.delegate = self;
- self.youpaipcollectionView.dataSource = self;
- //分割线
- UIView *viewLine =[UIView new];
- [self addSubview:viewLine];
- [viewLine mas_makeConstraints:^(MASConstraintMaker *make) {
- make.left.mas_equalTo(14);
- make.right.mas_equalTo(-14);
- make.bottom.mas_equalTo(0);
- make.height.mas_equalTo(0.5f);
- }];
- viewLine.backgroundColor =HexColorFromRGB(0x28262D);
- }
- -(void)setYoupaipdataArr:(NSArray *)dataArr{
- _youpaipdataArr = dataArr;
- self.youpaiptitleLabel.attributedText = [LCTools setRichTextWithTitle:@"已收藏" subTitle:[NSString stringWithFormat:@"(%lu人)",(unsigned long)self.youpaipdataArr.count] titleColor:[UIColor whiteColor] subTitleColor:HexColorFromRGB(0x9F9DA5) titleFontSize:14 subTitleFontSize:12];
- if (dataArr.count>0) {
-
- int count = 0;
- if(dataArr.count >= 5){
- count = 5;
- }else if(dataArr.count == 4){
- count = 4;
- }else if(dataArr.count == 3){
- count = 3;
- }else if(dataArr.count == 2){
- count = 2;
- }
- else {
- count = 1;
- }
-
- NSMutableArray *arr = [NSMutableArray new];
- for (int i = 0; i<count; i++) {
- [arr addObject:dataArr[i]];
- }
- _youpaipdataArr = arr;
- }
- }
- -(void)youpaifarrowBtnClick{
- // if ([self.delegate respondsToSelector:@selector(youpaifSHDidCellOrBtnclick:)]) {
- // [self.delegate youpaifSHDidCellOrBtnclick:NO];
- // }
-
- }
- -(void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath{
- // if (indexPath.item == self.dataArr.count) {
- // if ([self.delegate respondsToSelector:@selector(youpaifSHDidCellOrBtnclick:)]) {
- // [self.delegate youpaifSHDidCellOrBtnclick:YES];
- // }
- // }else{
- // if ([self.delegate respondsToSelector:@selector(youpaifSHDidCellOrBtnclick:)]) {
- // [self.delegate youpaifSHDidCellOrBtnclick:NO];
- // }
- // }
-
- }
- #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.youpaipdataArr.count+1;
- }
- -(UICollectionViewCell*)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
-
- YOUPAIZYUserZiLiaoBHPhotoCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:NSStringFromClass([YOUPAIZYUserZiLiaoBHPhotoCell class]) forIndexPath:indexPath];
-
- cell.backgroundColor = LCBkgColor;
- // if (indexPath.row == self.dataArr.count) {
- cell.youpaipiconImageView.image = [UIImage imageNamed:@"vqu_images_guard"];
-
- // }else{
- // NSString *imageUrl = self.dataArr[indexPath.item];
- // [cell.iconImageView sd_setImageWithURL:[NSURL URLWithString:imageUrl] placeholderImage:nil];
- //
- // }
- return cell;
- }
- #pragma mark UICollectionViewDelegateFlowLayout
- /**
- 项目大小
-
- @param collectionView 集合视图
- @param collectionViewLayout 布局
- @param indexPath 布局
- @return 大小
- */
- - (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath {
- return CGSizeMake(42, 42);
- }
- #pragma mark - X间距
- - (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout minimumInteritemSpacingForSectionAtIndex:(NSInteger)section {
- return 13.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
|