Files
featherVoice/QXLive/Mine(音域)/View/设置/QXSettingCell.m
2025-11-11 17:19:21 +08:00

216 lines
8.6 KiB
Objective-C

//
// QXSettingCell.m
// QXLive
//
// Created by 启星 on 2025/5/12.
//
#import "QXSettingCell.h"
@implementation QXSettingCell
+(instancetype)cellWithTableView:(UITableView *)tableView{
static NSString *cellId = @"QXSettingCell";
QXSettingCell *cell = [tableView dequeueReusableCellWithIdentifier:cellId];
if (!cell) {
cell = [[QXSettingCell alloc] initWithStyle:(UITableViewCellStyleDefault) reuseIdentifier:cellId];
}
return cell;
}
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
[self initSubviews];
}
return self;
}
-(void)setCellType:(QXSettingCellType )cellType{
_cellType = cellType;
switch (cellType) {
case QXSettingCellTypeNormal:{
self.detailLabel.hidden = NO;
self.rightArrow.hidden = NO;
self.btnSwitch.hidden = YES;
self.detailLabel.textAlignment = NSTextAlignmentRight;
[self.rightArrow mas_remakeConstraints:^(MASConstraintMaker *make) {
make.right.mas_equalTo(-16);
make.size.mas_equalTo(CGSizeMake(24, 24));
make.centerY.equalTo(self.contentView);
}];
[self.titleLabel mas_remakeConstraints:^(MASConstraintMaker *make) {
make.left.mas_equalTo(16);
make.centerY.equalTo(self.contentView);
make.right.equalTo(self.detailLabel.mas_left).offset(-10);
}];
[self.detailLabel mas_remakeConstraints:^(MASConstraintMaker *make) {
make.right.equalTo(self.rightArrow.mas_left).offset(-10);
make.centerY.equalTo(self.contentView);
make.width.mas_equalTo(120);
}];
}
break;
case QXSettingCellTypeOnlyArrow:{
self.detailLabel.hidden = YES;
self.rightArrow.hidden = NO;
self.rightConstraint.constant = 16;
self.btnSwitch.hidden = YES;
[self.rightArrow mas_remakeConstraints:^(MASConstraintMaker *make) {
make.right.mas_equalTo(-16);
make.size.mas_equalTo(CGSizeMake(24, 24));
make.centerY.equalTo(self.contentView);
}];
[self.titleLabel mas_remakeConstraints:^(MASConstraintMaker *make) {
make.left.mas_equalTo(16);
make.centerY.equalTo(self.contentView);
make.right.equalTo(self.rightArrow.mas_left).offset(-10);
}];
}
break;
case QXSettingCellTypeOnlyDetail:{
self.detailLabel.hidden = NO;
self.rightArrow.hidden = YES;
self.btnSwitch.hidden = YES;
self.detailLabel.textAlignment = NSTextAlignmentRight;
[self.detailLabel mas_remakeConstraints:^(MASConstraintMaker *make) {
make.right.mas_equalTo(-16);
make.centerY.equalTo(self.contentView);
make.width.mas_greaterThanOrEqualTo(120);
}];
[self.titleLabel mas_remakeConstraints:^(MASConstraintMaker *make) {
make.left.mas_equalTo(16);
make.centerY.equalTo(self.contentView);
make.right.equalTo(self.detailLabel.mas_left).offset(-10);
}];
}
break;
case QXSettingCellTypeSwitch:{
self.detailLabel.hidden = YES;
self.rightArrow.hidden = YES;
self.btnSwitch.hidden = NO;
[self.btnSwitch mas_remakeConstraints:^(MASConstraintMaker *make) {
make.right.mas_equalTo(-16);
make.size.mas_equalTo(CGSizeMake(40, 40));
make.centerY.equalTo(self.contentView);
}];
[self.titleLabel mas_remakeConstraints:^(MASConstraintMaker *make) {
make.left.mas_equalTo(16);
make.centerY.equalTo(self.contentView);
make.right.equalTo(self.btnSwitch.mas_left).offset(-10);
}];
}
break;
case QXSettingCellTypeTitleTopAndArrow:{
self.detailLabel.hidden = NO;
self.rightArrow.hidden = NO;
self.btnSwitch.hidden = YES;
self.detailLabel.textAlignment = NSTextAlignmentLeft;
[self.titleLabel mas_remakeConstraints:^(MASConstraintMaker *make) {
make.left.mas_equalTo(16);
make.top.mas_equalTo(9);
make.height.mas_equalTo(21);
make.right.equalTo(self.rightArrow.mas_left).offset(-10);
}];
[self.detailLabel mas_remakeConstraints:^(MASConstraintMaker *make) {
make.left.mas_equalTo(16);
make.top.equalTo(self.titleLabel.mas_bottom);
make.bottom.equalTo(self.contentView).offset(-9);
make.right.equalTo(self.rightArrow.mas_left).offset(-10);
}];
}
break;
case QXSettingCellTypeTitleTopNoArrow:{
self.detailLabel.hidden = NO;
self.rightArrow.hidden = YES;
self.btnSwitch.hidden = YES;
self.detailLabel.textAlignment = NSTextAlignmentLeft;
[self.titleLabel mas_remakeConstraints:^(MASConstraintMaker *make) {
make.left.mas_equalTo(16);
make.top.mas_equalTo(9);
make.height.mas_equalTo(21);
make.right.equalTo(self.contentView).offset(-10);
}];
[self.detailLabel mas_remakeConstraints:^(MASConstraintMaker *make) {
make.left.mas_equalTo(16);
make.top.equalTo(self.titleLabel.mas_bottom);
make.bottom.equalTo(self.contentView).offset(-9);
make.right.equalTo(self.contentView).offset(-10);
}];
}
break;
default:
break;
}
}
-(void)initSubviews{
self.rightArrow = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"arrowRight"]];
[self.contentView addSubview:self.rightArrow];
[self.rightArrow mas_makeConstraints:^(MASConstraintMaker *make) {
make.right.mas_equalTo(-16);
make.size.mas_equalTo(CGSizeMake(24, 24));
make.centerY.equalTo(self.contentView);
}];
self.btnSwitch = [[UIButton alloc] init];
[self.btnSwitch setImage:[UIImage imageNamed:@"home_switch_off"] forState:(UIControlStateNormal)];
[self.btnSwitch setImage:[UIImage imageNamed:@"home_switch_on"] forState:(UIControlStateSelected)];
// [self.btnSwitch addTarget:self action:@selector(btnSwitchAction:) forControlEvents:(UIControlEventTouchUpInside)];
[self.contentView addSubview:self.btnSwitch];
[self.btnSwitch mas_makeConstraints:^(MASConstraintMaker *make) {
make.right.mas_equalTo(-16);
make.size.mas_equalTo(CGSizeMake(40, 40));
make.centerY.equalTo(self.contentView);
}];
self.detailLabel = [[UILabel alloc] init];
self.detailLabel.font = [UIFont systemFontOfSize:13];
self.detailLabel.textAlignment = NSTextAlignmentRight;
self.detailLabel.textColor = RGB16(0x494949);
[self.contentView addSubview:self.detailLabel];
[self.detailLabel mas_makeConstraints:^(MASConstraintMaker *make) {
make.right.equalTo(self.rightArrow.mas_left).offset(-10);
make.centerY.equalTo(self.contentView);
make.width.mas_equalTo(120);
}];
self.titleLabel = [[UILabel alloc] init];
self.titleLabel.font = [UIFont systemFontOfSize:14];
self.titleLabel.textColor = RGB16(0x333333);
[self.contentView addSubview:self.titleLabel];
[self.titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.mas_equalTo(16);
make.centerY.equalTo(self.contentView);
make.right.equalTo(self.detailLabel.mas_left).offset(-10);
}];
self.lineView = [[UIView alloc] init];
self.lineView.backgroundColor = [UIColor lightGrayColor];
[self.contentView addSubview:self.lineView];
[self.lineView mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.mas_equalTo(16);
make.right.mas_equalTo(-16);
make.height.mas_equalTo(0.5);
make.bottom.equalTo(self.contentView);
}];
}
-(void)setNeedLine:(BOOL)needLine{
_needLine = needLine;
self.lineView.hidden = !needLine;
}
//- (void)btnSwitchAction:(UIButton *)sender {
//// sender.selected = !sender.selected;
//}
- (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