// // ASMineAddressCell.m // Asteria // // Created by iOS on 2024/5/7. // #import "ASMineAddressCell.h" @interface ASMineAddressCell () @property (nonatomic, strong) UIView *bgV; @property (nonatomic, strong) UILabel *nameLB; @property (nonatomic, strong) UILabel *addressLB; @property (nonatomic, strong) UILabel *codeLB; @property (nonatomic, strong) UILabel *countryLB; @property (nonatomic, strong) UILabel *phoneLB; @end @implementation ASMineAddressCell - (void)setData:(ASAddressModel *)m { if (m.title && ![m.title isEmpty]) { self.titleLB.text = m.title; } else { self.titleLB.text = @"Other Address"; } self.nameLB.text = [NSString stringWithFormat:@"%@ %@",m.lastname,m.firstname]; NSString *street = [m.street componentsJoinedByString:@" "]; self.addressLB.text = [NSString stringWithFormat:@"%@,%@,%@",m.city,m.region.region,street]; self.codeLB.text = m.postcode;//[NSString stringWithFormat:@""] self.countryLB.text = m.country; self.phoneLB.text = [NSString stringWithFormat:@"T:%@",m.telephone]; } - (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier { self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]; if (self) { [self configSubV]; } return self; } - (void)configSubV { self.backgroundColor = [UIColor whiteColor]; self.selectionStyle = UITableViewCellSelectionStyleNone; self.bgV = [UIView new]; self.bgV.backgroundColor = _F8F8F8; // self.bgV.layer.cornerRadius = 4; // self.bgV.layer.masksToBounds = true; [self.contentView addSubview:self.bgV]; [self.bgV mas_makeConstraints:^(MASConstraintMaker *make) { make.top.equalTo(self.contentView).offset(0); make.left.equalTo(self.contentView).offset(0); make.centerX.equalTo(self.contentView); make.bottom.equalTo(self.contentView).offset(-10); }]; self.titleLB = [self createLb]; self.titleLB.font = [UIFont fontWithName:Rob_Bold size:16]; self.titleLB.numberOfLines =0; self.titleLB.preferredMaxLayoutWidth = KScreenWidth-40-10-44; [self.bgV addSubview:self.titleLB]; [self.titleLB mas_makeConstraints:^(MASConstraintMaker *make) { make.top.equalTo(self.bgV).offset(20); make.left.equalTo(self.bgV).offset(15); make.width.mas_equalTo(KScreenWidth-40-10-44); }]; self.editBt = [UIButton buttonWithType:UIButtonTypeCustom]; [self.editBt setImage:[UIImage imageNamed:@"avater_edit"] forState:UIControlStateNormal]; [self.editBt addTarget:self action:@selector(editBtnAction) forControlEvents:UIControlEventTouchUpInside]; [self.bgV addSubview:self.editBt]; [self.editBt mas_makeConstraints:^(MASConstraintMaker *make) { make.width.height.equalTo(@44); make.right.equalTo(self.bgV); make.centerY.equalTo(self.bgV); }]; self.checkBtn = [UIButton buttonWithType:UIButtonTypeCustom]; self.checkBtn.hidden = YES; [self.checkBtn setImage:[UIImage imageNamed:@"cartship_radio_unselect"] forState:UIControlStateNormal]; [self.checkBtn setImage:[UIImage imageNamed:@"cartship_radio_select"] forState:UIControlStateSelected]; [self.checkBtn addTarget:self action:@selector(handle_checkBtnAction) forControlEvents:UIControlEventTouchUpInside]; [self.bgV addSubview:self.checkBtn]; [self.checkBtn mas_makeConstraints:^(MASConstraintMaker *make) { make.height.equalTo(@44); make.width.equalTo(@44); make.right.equalTo(self.bgV); make.centerY.equalTo(self.titleLB); }]; UIStackView *tStackV = [[UIStackView alloc] init]; tStackV.axis = UILayoutConstraintAxisVertical; tStackV.alignment = UIStackViewAlignmentFill; tStackV.distribution = UIStackViewDistributionFill; tStackV.spacing = 10; [self.bgV addSubview:tStackV]; [tStackV mas_makeConstraints:^(MASConstraintMaker *make) { make.top.equalTo(self.titleLB.mas_bottom).offset(15); make.left.equalTo(self.bgV).offset(15); make.right.equalTo(self.editBt.mas_left).offset(-15); make.bottom.equalTo(self.bgV).offset(-20); }]; self.nameLB = [self createLb]; [tStackV addArrangedSubview:self.nameLB]; self.addressLB = [self createLb]; [tStackV addArrangedSubview:self.addressLB]; self.addressLB.numberOfLines = 0; self.codeLB = [self createLb]; [tStackV addArrangedSubview:self.codeLB]; self.countryLB = [self createLb]; [tStackV addArrangedSubview:self.countryLB]; self.phoneLB = [self createLb]; [tStackV addArrangedSubview:self.phoneLB]; } - (void)editBtnAction { if (self.editBack) { self.editBack(); } } -(void)handle_checkBtnAction{ if(self.checkBack){ self.checkBack(); } } - (UILabel *)createLb { UILabel *lb = [[UILabel alloc] init]; lb.font = [UIFont fontWithName:Rob_Regular size:14]; lb.textColor = UIColor.blackColor; [lb mas_makeConstraints:^(MASConstraintMaker *make) { make.height.greaterThanOrEqualTo(@14); }]; return lb; } - (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