This commit is contained in:
2025-11-14 19:48:15 +08:00
parent 4f2e80e482
commit dace0a9309
21 changed files with 792 additions and 19 deletions

View File

@@ -0,0 +1,162 @@
//
// KBVipSubscribeCell.m
// keyBoard
//
// 使 mas +
//
#import "KBVipSubscribeCell.h"
@interface KBVipSubscribeCell ()
@property (nonatomic, strong) UIView *cardView; //
@property (nonatomic, strong) UILabel *titleLabel; // Monthly Subscription
@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
- (instancetype)initWithFrame:(CGRect)frame {
if (self = [super initWithFrame:frame]) {
self.contentView.backgroundColor = [UIColor clearColor];
[self.contentView addSubview:self.cardView];
[self.cardView mas_makeConstraints:^(MASConstraintMaker *make) {
make.edges.equalTo(self.contentView);
}];
[self.cardView addSubview:self.titleLabel];
[self.cardView addSubview:self.priceLabel];
[self.cardView addSubview:self.strikeLabel];
[self.cardView addSubview:self.selectButton];
[self.titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.equalTo(self.cardView).offset(16);
make.top.equalTo(self.cardView).offset(16);
}];
[self.priceLabel mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.equalTo(self.titleLabel);
make.top.equalTo(self.titleLabel.mas_bottom).offset(6);
}];
[self.strikeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.equalTo(self.priceLabel.mas_right).offset(10);
make.centerY.equalTo(self.priceLabel);
}];
[self.selectButton mas_makeConstraints:^(MASConstraintMaker *make) {
make.centerY.equalTo(self.cardView);
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];
}
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 {
[super prepareForReuse];
[self applySelected:NO animated:NO];
}
- (void)setSelected:(BOOL)selected {
[super setSelected:selected];
[self applySelected:selected animated:NO];
}
- (void)configTitle:(NSString *)title price:(NSString *)price strike:(nullable NSString *)strike {
self.titleLabel.text = title.length ? title : @"Monthly Subscription";
self.priceLabel.text = price.length ? price : @"$4.49";
self.strikeLabel.hidden = (strike.length == 0);
if (strike.length) {
// 线
NSDictionary *attr = @{
NSStrikethroughStyleAttributeName: @(NSUnderlineStyleSingle),
NSForegroundColorAttributeName: [UIColor colorWithWhite:0.7 alpha:1.0]
};
self.strikeLabel.attributedText = [[NSAttributedString alloc] initWithString:strike attributes:attr];
}
}
- (void)applySelected:(BOOL)selected animated:(BOOL)animated {
UIImage *img = [UIImage imageNamed:(selected ? @"pay_circle_sel" : @"pay_circle_normal")];
[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);
};
if (animated) {
[UIView animateWithDuration:0.15 animations:changes];
} else {
changes();
}
}
#pragma mark - Lazy
- (UIView *)cardView {
if (!_cardView) {
_cardView = [UIView new];
_cardView.backgroundColor = [UIColor whiteColor];
}
return _cardView;
}
- (UILabel *)titleLabel {
if (!_titleLabel) {
_titleLabel = [UILabel new];
_titleLabel.text = @"Monthly Subscription";
_titleLabel.textColor = [UIColor colorWithHex:KBBlackValue];
_titleLabel.font = [UIFont systemFontOfSize:16 weight:UIFontWeightSemibold];
}
return _titleLabel;
}
- (UILabel *)priceLabel {
if (!_priceLabel) {
_priceLabel = [UILabel new];
_priceLabel.text = @"$4.49";
_priceLabel.textColor = [UIColor colorWithHex:KBBlackValue];
_priceLabel.font = [UIFont systemFontOfSize:28 weight:UIFontWeightBold];
}
return _priceLabel;
}
- (UILabel *)strikeLabel {
if (!_strikeLabel) {
_strikeLabel = [UILabel new];
_strikeLabel.text = @"$4.49";
_strikeLabel.font = [UIFont systemFontOfSize:16 weight:UIFontWeightSemibold];
_strikeLabel.textColor = [UIColor colorWithWhite:0.7 alpha:1.0];
}
return _strikeLabel;
}
- (UIButton *)selectButton {
if (!_selectButton) {
_selectButton = [UIButton buttonWithType:UIButtonTypeCustom];
[_selectButton setImage:[UIImage imageNamed:@"pay_circle_normal"] forState:UIControlStateNormal];
_selectButton.userInteractionEnabled = NO; //
_selectButton.contentMode = UIViewContentModeCenter;
}
return _selectButton;
}
@end