// // QXMineServiceCell.m // QXLive // // Created by 启星 on 2025/5/9. // #import "QXMineServiceCell.h" @class QXMineServiceSubCell; @interface QXMineServiceCell() @property (nonatomic,strong)UIView *bgView; @property (nonatomic,strong)UILabel *titleLabel; @property (nonatomic,strong)UICollectionView *collectionView; @property (nonatomic,strong)NSMutableArray *serviceArray; @property (nonatomic,strong)NSMutableArray *serviceImageArray; @end @implementation QXMineServiceCell +(instancetype)cellWithTableView:(UITableView *)tableView{ static NSString *cellId = @"QXMineServiceCell"; QXMineServiceCell *cell = [tableView dequeueReusableCellWithIdentifier:cellId]; if (!cell) { cell = [[QXMineServiceCell alloc] initWithStyle:(UITableViewCellStyleDefault) reuseIdentifier:cellId]; } return cell; } -(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{ if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) { self.selectionStyle = UITableViewCellSelectionStyleNone; self.backgroundColor = [UIColor clearColor]; [self createViews]; } return self; } -(void)createViews{ self.bgView = [[UIView alloc] init]; self.bgView.backgroundColor = [UIColor whiteColor]; [self.bgView addRoundedCornersWithRadius:10]; [self.contentView addSubview:self.bgView]; [self.bgView mas_makeConstraints:^(MASConstraintMaker *make) { make.left.mas_equalTo(16); make.right.mas_equalTo(-16); make.top.bottom.equalTo(self); }]; self.titleLabel = [[UILabel alloc] init]; self.titleLabel.font = [UIFont boldSystemFontOfSize:16]; self.titleLabel.textColor = QXConfig.textColor; self.titleLabel.text = QXText(@"更多服务"); [self.bgView addSubview:self.titleLabel];; [self.titleLabel mas_makeConstraints:^(MASConstraintMaker *make) { make.top.left.mas_equalTo(12); make.right.mas_equalTo(-12); make.height.mas_equalTo(24); }]; NSInteger maxCount = 4; CGFloat btnWith = (int)(SCREEN_WIDTH-32-1)/maxCount; CGFloat btnHeight = 44; UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc] init]; layout.itemSize = CGSizeMake(btnWith, btnHeight); layout.minimumLineSpacing = 10; layout.minimumInteritemSpacing = 0; layout.sectionInset = UIEdgeInsetsMake(0, 0, 0, 0); layout.scrollDirection = UICollectionViewScrollDirectionVertical; self.collectionView = [[UICollectionView alloc] initWithFrame:CGRectZero collectionViewLayout:layout]; [self.collectionView registerClass:[QXMineServiceSubCell class] forCellWithReuseIdentifier:@"QXMineServiceSubCell"]; self.collectionView.delegate = self; self.collectionView.dataSource = self; self.collectionView.showsHorizontalScrollIndicator = NO; self.collectionView.bounces = NO; self.collectionView.backgroundColor = UIColor.clearColor; [self.bgView addSubview:self.collectionView]; [self.collectionView mas_makeConstraints:^(MASConstraintMaker *make) { make.left.right.equalTo(self.bgView); make.top.equalTo(self.titleLabel.mas_bottom).offset(22); make.height.mas_equalTo(btnHeight*2+10); // make.right.mas_equalTo(-12); }]; // for (int i = 0; i < self.serviceArray.count; i++) { // NSInteger col = i / maxCount; // NSInteger line = i % maxCount; // UIButton *btn = [[UIButton alloc] init]; // [self.bgView addSubview:btn]; // [btn setTitle:self.serviceArray[i] forState:(UIControlStateNormal)]; // [btn setTitleColor:[UIColor clearColor] forState:(UIControlStateNormal)]; // [btn addTarget:self action:@selector(serviceClick:) forControlEvents:(UIControlEventTouchUpInside)]; // [btn mas_makeConstraints:^(MASConstraintMaker *make) { // make.left.mas_equalTo(line*btnWith); // make.top.equalTo(self.titleLabel.mas_bottom).offset(13+col*(btnHeight+13)); // make.height.mas_equalTo(btnHeight); // make.width.mas_equalTo(btnWith); // }]; // // // // } } -(void)serviceClick:(UIButton*)sender{ if (self.delegate && [self.delegate respondsToSelector:@selector(didClickServiceWithBtn:title:)]) { [self.delegate didClickServiceWithBtn:sender title:sender.titleLabel.text]; } } -(NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{ return self.serviceArray.count; } -(__kindof UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{ QXMineServiceSubCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"QXMineServiceSubCell" forIndexPath:indexPath]; cell.imageView.image = [UIImage imageNamed:self.serviceImageArray[indexPath.row]]; cell.titleLabel.text = self.serviceArray[indexPath.row]; return cell; } -(void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath{ if (self.delegate && [self.delegate respondsToSelector:@selector(didClickServiceWithBtn:title:)]) { [self.delegate didClickServiceWithBtn:nil title:self.serviceArray[indexPath.row]]; } } -(void)cellReload{ if (QXGlobal.shareGlobal.isOpenRecharge){ if ([self.serviceArray containsObject:QXText(@"每日任务")]) { return; } [self.serviceArray addObject:QXText(@"每日任务")]; [self.serviceImageArray addObject:@"service_task"]; [self.collectionView reloadData]; } } -(NSMutableArray *)serviceArray{ if (!_serviceArray) { _serviceArray = [NSMutableArray arrayWithArray:@[ QXText(@"钱包"), QXText(@"段位"), QXText(@"公会中心"), QXText(@"个性装扮"), QXText(@"道具商城"), QXText(@"我的背包"), ]]; } return _serviceArray; } -(NSMutableArray *)serviceImageArray{ if (!_serviceImageArray) { _serviceImageArray = [NSMutableArray arrayWithArray:@[ @"service_wallet", @"service_level", @"service_guild", @"service_dress", @"service_shop", @"service_bag", ]]; } return _serviceImageArray; } - (void)awakeFromNib { [super awakeFromNib]; // Initialization code } - (void)setSelected:(BOOL)selected animated:(BOOL)animated { [super setSelected:selected animated:animated]; // Configure the view for the selected state } @end @implementation QXMineServiceSubCell - (instancetype)initWithFrame:(CGRect)frame { self = [super initWithFrame:frame]; if (self) { [self initSubviews]; } return self; } -(void)initSubviews{ UIImageView *imageView = [[UIImageView alloc] init]; [self.contentView addSubview:imageView]; self.imageView = imageView; [imageView mas_makeConstraints:^(MASConstraintMaker *make) { make.top.centerX.equalTo(self.contentView); make.height.width.mas_equalTo(18); }]; UILabel *titleLabel = [[UILabel alloc] init]; titleLabel.textColor = QXConfig.textColor; titleLabel.font = [UIFont systemFontOfSize:12]; [self.contentView addSubview:titleLabel]; self.titleLabel = titleLabel; [titleLabel mas_makeConstraints:^(MASConstraintMaker *make) { make.top.equalTo(imageView.mas_bottom).offset(3); make.centerX.equalTo(self.contentView); make.height.mas_equalTo(17); }]; } @end