Files
featherVoice/QXLive/Mine(音域)/View/QXMineServiceCell.m
2025-08-08 10:49:36 +08:00

138 lines
4.8 KiB
Objective-C

//
// QXMineServiceCell.m
// QXLive
//
// Created by 启星 on 2025/5/9.
//
#import "QXMineServiceCell.h"
@interface QXMineServiceCell()
@property (nonatomic,strong)UIView *bgView;
@property (nonatomic,strong)UILabel *titleLabel;
@property (nonatomic,strong)NSArray *serviceArray;
@property (nonatomic,strong)NSArray *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 = (SCREEN_WIDTH-32)/maxCount;
CGFloat btnHeight = 44;
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);
}];
UIImageView *imageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:self.serviceImageArray[i]]];
[self.bgView addSubview:imageView];
[imageView mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.centerX.equalTo(btn);
make.height.width.mas_equalTo(18);
}];
UILabel *titleLabel = [[UILabel alloc] init];
titleLabel.textColor = QXConfig.textColor;
titleLabel.text = self.serviceArray[i];
titleLabel.font = [UIFont systemFontOfSize:12];
[self.bgView addSubview:titleLabel];
[titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.equalTo(imageView.mas_bottom).offset(3);
make.centerX.equalTo(btn);
make.height.mas_equalTo(17);
}];
}
}
-(void)serviceClick:(UIButton*)sender{
if (self.delegate && [self.delegate respondsToSelector:@selector(didClickServiceWithBtn:title:)]) {
[self.delegate didClickServiceWithBtn:sender title:sender.titleLabel.text];
}
}
-(NSArray *)serviceArray{
if (!_serviceArray) {
_serviceArray = @[
QXText(@"钱包"),
QXText(@"段位"),
QXText(@"公会中心"),
QXText(@"个性装扮"),
QXText(@"道具商城"),
QXText(@"我的背包"),
QXText(@"每日任务"),
];
}
return _serviceArray;
}
-(NSArray *)serviceImageArray{
if (!_serviceImageArray) {
_serviceImageArray = @[
@"service_wallet",
@"service_level",
@"service_guild",
@"service_dress",
@"service_shop",
@"service_bag",
@"service_task",
];
}
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