1
This commit is contained in:
@@ -13,7 +13,6 @@
|
||||
@property (nonatomic, strong) UILabel *priceLabel; // “$4.49”
|
||||
@property (nonatomic, strong) UILabel *strikeLabel; // 删除线原价
|
||||
@property (nonatomic, strong) UIButton *selectButton; // 右侧选择按钮
|
||||
@property (nonatomic, strong) CAShapeLayer *borderLayer; // 选中边框
|
||||
@end
|
||||
|
||||
@implementation KBVipSubscribeCell
|
||||
@@ -23,8 +22,12 @@
|
||||
self.contentView.backgroundColor = [UIColor clearColor];
|
||||
|
||||
[self.contentView addSubview:self.cardView];
|
||||
// self.cardView.backgroundColor = [UIColor redColor];
|
||||
[self.cardView mas_makeConstraints:^(MASConstraintMaker *make) {
|
||||
make.edges.equalTo(self.contentView);
|
||||
make.left.right.equalTo(self.contentView);
|
||||
make.top.equalTo(self.contentView).inset(6);
|
||||
make.bottom.equalTo(self.contentView);
|
||||
|
||||
}];
|
||||
|
||||
[self.cardView addSubview:self.titleLabel];
|
||||
@@ -34,7 +37,7 @@
|
||||
|
||||
[self.titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
|
||||
make.left.equalTo(self.cardView).offset(16);
|
||||
make.top.equalTo(self.cardView).offset(16);
|
||||
make.top.equalTo(self.cardView).offset(11);
|
||||
}];
|
||||
[self.priceLabel mas_makeConstraints:^(MASConstraintMaker *make) {
|
||||
make.left.equalTo(self.titleLabel);
|
||||
@@ -49,27 +52,16 @@
|
||||
make.right.equalTo(self.cardView).offset(-16);
|
||||
make.width.height.mas_equalTo(28);
|
||||
}];
|
||||
|
||||
// 边框层(选中时显示主题绿)
|
||||
self.borderLayer = [CAShapeLayer layer];
|
||||
self.borderLayer.strokeColor = [UIColor colorWithWhite:0.9 alpha:1.0].CGColor;
|
||||
// 使用透明填充,避免遮挡内部子视图;只显示描边
|
||||
self.borderLayer.fillColor = UIColor.clearColor.CGColor;
|
||||
self.borderLayer.lineWidth = 1.5;
|
||||
// 放到底层,避免盖住 label/button(修复滚动后偶现内容被遮挡变空白)
|
||||
[self.cardView.layer insertSublayer:self.borderLayer atIndex:0];
|
||||
// 基于 CALayer 的边框(替代 borderLayer)
|
||||
self.cardView.layer.borderWidth = 1;
|
||||
self.cardView.layer.borderColor = [UIColor colorWithWhite:0.9 alpha:1.0].CGColor;
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
- (void)layoutSubviews {
|
||||
[super layoutSubviews];
|
||||
CGFloat radius = 16;
|
||||
UIBezierPath *path = [UIBezierPath bezierPathWithRoundedRect:self.cardView.bounds cornerRadius:radius];
|
||||
self.cardView.layer.cornerRadius = radius;
|
||||
self.cardView.layer.masksToBounds = YES;
|
||||
self.borderLayer.frame = self.cardView.bounds;
|
||||
self.borderLayer.path = path.CGPath;
|
||||
|
||||
}
|
||||
|
||||
- (void)prepareForReuse {
|
||||
@@ -101,17 +93,13 @@
|
||||
[self.selectButton setImage:img forState:UIControlStateNormal];
|
||||
CGColorRef color = (selected ? [UIColor colorWithHex:KBColorValue].CGColor : [UIColor colorWithWhite:0.9 alpha:1.0].CGColor);
|
||||
void (^changes)(void) = ^{
|
||||
self.borderLayer.strokeColor = color;
|
||||
self.cardView.layer.shadowOpacity = selected ? 0.12 : 0.0;
|
||||
self.cardView.layer.shadowColor = [UIColor colorWithHex:KBColorValue].CGColor;
|
||||
self.cardView.layer.shadowRadius = selected ? 8 : 0;
|
||||
self.cardView.layer.shadowOffset = CGSizeMake(0, selected ? 4 : 0);
|
||||
self.cardView.layer.borderColor = color;
|
||||
// self.cardView.layer.shadowOpacity = selected ? 0.12 : 0.0;
|
||||
// self.cardView.layer.shadowColor = [UIColor colorWithHex:KBColorValue].CGColor;
|
||||
// self.cardView.layer.shadowRadius = selected ? 8 : 0;
|
||||
// self.cardView.layer.shadowOffset = CGSizeMake(0, selected ? 4 : 0);
|
||||
};
|
||||
if (animated) {
|
||||
[UIView animateWithDuration:0.15 animations:changes];
|
||||
} else {
|
||||
changes();
|
||||
}
|
||||
}
|
||||
|
||||
#pragma mark - Lazy
|
||||
@@ -119,6 +107,9 @@
|
||||
if (!_cardView) {
|
||||
_cardView = [UIView new];
|
||||
_cardView.backgroundColor = [UIColor whiteColor];
|
||||
CGFloat radius = 10;
|
||||
_cardView.layer.cornerRadius = radius;
|
||||
_cardView.clipsToBounds = YES;
|
||||
}
|
||||
return _cardView;
|
||||
}
|
||||
@@ -127,7 +118,7 @@
|
||||
_titleLabel = [UILabel new];
|
||||
_titleLabel.text = @"Monthly Subscription";
|
||||
_titleLabel.textColor = [UIColor colorWithHex:KBBlackValue];
|
||||
_titleLabel.font = [UIFont systemFontOfSize:16 weight:UIFontWeightSemibold];
|
||||
_titleLabel.font = [UIFont systemFontOfSize:13 weight:UIFontWeightSemibold];
|
||||
}
|
||||
return _titleLabel;
|
||||
}
|
||||
@@ -136,7 +127,7 @@
|
||||
_priceLabel = [UILabel new];
|
||||
_priceLabel.text = @"$4.49";
|
||||
_priceLabel.textColor = [UIColor colorWithHex:KBBlackValue];
|
||||
_priceLabel.font = [UIFont systemFontOfSize:28 weight:UIFontWeightBold];
|
||||
_priceLabel.font = [UIFont systemFontOfSize:20 weight:UIFontWeightBold];
|
||||
}
|
||||
return _priceLabel;
|
||||
}
|
||||
@@ -144,7 +135,7 @@
|
||||
if (!_strikeLabel) {
|
||||
_strikeLabel = [UILabel new];
|
||||
_strikeLabel.text = @"$4.49";
|
||||
_strikeLabel.font = [UIFont systemFontOfSize:16 weight:UIFontWeightSemibold];
|
||||
_strikeLabel.font = [UIFont systemFontOfSize:20 weight:UIFontWeightSemibold];
|
||||
_strikeLabel.textColor = [UIColor colorWithWhite:0.7 alpha:1.0];
|
||||
}
|
||||
return _strikeLabel;
|
||||
|
||||
Reference in New Issue
Block a user