// // ASCheckoutTopView.m // Asteria // // Created by xingyu on 2024/5/8. // #import "ASCheckoutTopView.h" @implementation ASCheckoutTopView - (instancetype)initWithFrame:(CGRect)frame { if (self = [super initWithFrame:frame]) { self.backgroundColor = ThemeLightColor; [self addSubview:self.countLab]; [self addSubview:self.arrowBtn]; [self addSubview:self.priceLab]; [self.countLab mas_makeConstraints:^(MASConstraintMaker *make) { make.left.mas_equalTo(20); make.centerY.equalTo(self); }]; [self.arrowBtn mas_makeConstraints:^(MASConstraintMaker *make) { make.right.mas_equalTo(-12); make.centerY.equalTo(self); make.width.mas_equalTo(35); make.height.mas_equalTo(32); }]; [self.priceLab mas_makeConstraints:^(MASConstraintMaker *make) { make.right.equalTo(self.arrowBtn.mas_left).offset(-6); make.centerY.equalTo(self); }]; } return self; } - (void)setTopViewData:(NSString *)itemCount price:(NSString *)priceStr { self.countLab.text = [NSString stringWithFormat:@"show order items (%@)", AS_String_valid(itemCount) ? AS_String_NotNull(itemCount) : @"0"]; self.priceLab.text = priceStr; } - (void)_isFlodClick:(UIButton *)button { button.selected = !button.selected; if (self.isFlodBlock) { self.isFlodBlock(button.selected); } } - (UILabel *)countLab { if (!_countLab) { _countLab = [[UILabel alloc] init]; _countLab.textColor = _0B0B0B; _countLab.text = @"show order items"; _countLab.font = [UIFont fontWithName:Rob_Bold size:16]; } return _countLab; } - (UIButton *)arrowBtn { if (!_arrowBtn) { _arrowBtn = [UIButton buttonWithType:UIButtonTypeCustom]; [_arrowBtn setImage:[UIImage imageNamed:@"checkout_arrow_up"] forState:UIControlStateNormal]; [_arrowBtn setImage:[UIImage imageNamed:@"checkout_arrow_down"] forState:UIControlStateSelected]; _arrowBtn.titleLabel.font = [UIFont fontWithName:Rob_Bold size:12]; [_arrowBtn addTarget:self action:@selector(_isFlodClick:) forControlEvents:UIControlEventTouchUpInside]; [_arrowBtn setTitleColor:_0B0B0B forState:0]; } return _arrowBtn; } - (UILabel *)priceLab { if (!_priceLab) { _priceLab = [[UILabel alloc] init]; _priceLab.textColor = _0B0B0B; _priceLab.font = [UIFont fontWithName:Rob_Bold size:16]; } return _priceLab; } @end