This commit is contained in:
2025-12-17 19:45:39 +08:00
parent 8bad475288
commit 886de394d0
10 changed files with 207 additions and 36 deletions

View File

@@ -11,8 +11,7 @@
@property (nonatomic, strong) UILabel *titleLabel;
@property (nonatomic, strong) UILabel *priceLabel;
@property (nonatomic, strong) UILabel *strikeLabel;
@property (nonatomic, strong) UIView *checkBadge;
@property (nonatomic, strong) UILabel *checkLabel;
@property (nonatomic, strong) UIImageView *selectedImageView;
@end
@implementation KBKeyboardSubscriptionOptionCell
- (instancetype)initWithFrame:(CGRect)frame {
@@ -22,8 +21,7 @@
[self.cardView addSubview:self.titleLabel];
[self.cardView addSubview:self.priceLabel];
[self.cardView addSubview:self.strikeLabel];
[self.cardView addSubview:self.checkBadge];
[self.checkBadge addSubview:self.checkLabel];
[self.cardView addSubview:self.selectedImageView];
[self.cardView mas_makeConstraints:^(MASConstraintMaker *make) {
// make.edges.equalTo(self.contentView);
@@ -32,7 +30,7 @@
}];
[self.titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.equalTo(self.cardView.mas_top).offset(4);
make.top.equalTo(self.cardView.mas_top).offset(8);
make.left.equalTo(self.cardView.mas_left).offset(10);
make.right.equalTo(self.cardView.mas_right).offset(-10);
}];
@@ -47,14 +45,11 @@
make.centerY.equalTo(self.priceLabel);
}];
[self.checkBadge mas_makeConstraints:^(MASConstraintMaker *make) {
[self.selectedImageView mas_makeConstraints:^(MASConstraintMaker *make) {
make.centerX.equalTo(self.cardView.mas_centerX);
make.bottom.equalTo(self.cardView.mas_bottom).offset(10);
make.width.height.mas_equalTo(20);
}];
[self.checkLabel mas_makeConstraints:^(MASConstraintMaker *make) {
make.center.equalTo(self.checkBadge);
make.width.mas_equalTo(16);
make.height.mas_equalTo(17);
}];
}
return self;
@@ -92,13 +87,16 @@
void (^changes)(void) = ^{
self.cardView.layer.borderColor = selected ? [UIColor colorWithHex:0x02BEAC].CGColor : [[UIColor blackColor] colorWithAlphaComponent:0.12].CGColor;
self.cardView.layer.borderWidth = selected ? 2.0 : 1.0;
self.checkBadge.backgroundColor = selected ? [UIColor colorWithHex:0x02BEAC] : [[UIColor blackColor] colorWithAlphaComponent:0.15];
self.checkLabel.textColor = [UIColor whiteColor];
self.selectedImageView.alpha = selected ? 1.0 : 0.0;
};
if (animated) {
[UIView animateWithDuration:0.18 animations:changes];
self.selectedImageView.hidden = NO;
[UIView animateWithDuration:0.18 animations:changes completion:^(BOOL finished) {
self.selectedImageView.hidden = !selected;
}];
} else {
changes();
self.selectedImageView.hidden = !selected;
}
}
@@ -141,23 +139,13 @@
return _strikeLabel;
}
- (UIView *)checkBadge {
if (!_checkBadge) {
_checkBadge = [[UIView alloc] init];
_checkBadge.layer.cornerRadius = 10;
_checkBadge.backgroundColor = [[UIColor blackColor] colorWithAlphaComponent:0.15];
- (UIImageView *)selectedImageView {
if (!_selectedImageView) {
_selectedImageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"buy_sel_icon"]];
_selectedImageView.contentMode = UIViewContentModeScaleAspectFit;
_selectedImageView.hidden = YES;
_selectedImageView.alpha = 0.0;
}
return _checkBadge;
}
- (UILabel *)checkLabel {
if (!_checkLabel) {
_checkLabel = [[UILabel alloc] init];
_checkLabel.text = @"✓";
_checkLabel.font = [UIFont systemFontOfSize:12 weight:UIFontWeightBold];
_checkLabel.textColor = [UIColor whiteColor];
_checkLabel.textAlignment = NSTextAlignmentCenter;
}
return _checkLabel;
return _selectedImageView;
}
@end