Files
keyboard/CustomKeyboard/View/Buy/KBKeyboardSubscriptionOptionCell.m

152 lines
5.4 KiB
Mathematica
Raw Normal View History

2025-12-17 19:08:44 +08:00
//
// KBKeyboardSubscriptionOptionCell.m
// CustomKeyboard
//
// Created by Mac on 2025/12/17.
//
#import "KBKeyboardSubscriptionOptionCell.h"
@interface KBKeyboardSubscriptionOptionCell()
@property (nonatomic, strong) UIView *cardView;
@property (nonatomic, strong) UILabel *titleLabel;
@property (nonatomic, strong) UILabel *priceLabel;
@property (nonatomic, strong) UILabel *strikeLabel;
2025-12-17 19:45:39 +08:00
@property (nonatomic, strong) UIImageView *selectedImageView;
2025-12-17 19:08:44 +08:00
@end
@implementation KBKeyboardSubscriptionOptionCell
- (instancetype)initWithFrame:(CGRect)frame {
if (self = [super initWithFrame:frame]) {
self.contentView.backgroundColor = [UIColor clearColor];
[self.contentView addSubview:self.cardView];
[self.cardView addSubview:self.titleLabel];
[self.cardView addSubview:self.priceLabel];
[self.cardView addSubview:self.strikeLabel];
2025-12-17 19:45:39 +08:00
[self.cardView addSubview:self.selectedImageView];
2025-12-17 19:08:44 +08:00
[self.cardView mas_makeConstraints:^(MASConstraintMaker *make) {
// make.edges.equalTo(self.contentView);
make.left.right.top.equalTo(self.contentView);
make.bottom.equalTo(self.contentView).offset(-10);
}];
[self.titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
2025-12-17 19:45:39 +08:00
make.top.equalTo(self.cardView.mas_top).offset(8);
2025-12-17 19:08:44 +08:00
make.left.equalTo(self.cardView.mas_left).offset(10);
make.right.equalTo(self.cardView.mas_right).offset(-10);
}];
[self.priceLabel mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.equalTo(self.titleLabel.mas_left);
make.top.equalTo(self.titleLabel.mas_bottom).offset(8);
}];
[self.strikeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.equalTo(self.priceLabel.mas_right).offset(5);
make.centerY.equalTo(self.priceLabel);
}];
2025-12-17 19:45:39 +08:00
[self.selectedImageView mas_makeConstraints:^(MASConstraintMaker *make) {
2025-12-17 19:08:44 +08:00
make.centerX.equalTo(self.cardView.mas_centerX);
make.bottom.equalTo(self.cardView.mas_bottom).offset(10);
2025-12-17 19:45:39 +08:00
make.width.mas_equalTo(16);
make.height.mas_equalTo(17);
2025-12-17 19:08:44 +08:00
}];
}
return self;
}
- (void)prepareForReuse {
[super prepareForReuse];
self.titleLabel.text = @"";
self.priceLabel.text = @"";
self.strikeLabel.attributedText = nil;
self.strikeLabel.hidden = YES;
[self applySelected:NO animated:NO];
}
- (void)configureWithProduct:(KBKeyboardSubscriptionProduct *)product {
if (!product) { return; }
self.titleLabel.text = [product displayTitle];
self.priceLabel.text = [product priceDisplayText];
NSString *strike = [product strikePriceDisplayText];
if (strike.length > 0) {
NSDictionary *attr = @{
NSStrikethroughStyleAttributeName: @(NSUnderlineStyleSingle),
NSForegroundColorAttributeName: [UIColor colorWithHex:0xCCCCCC],
NSFontAttributeName: [UIFont systemFontOfSize:14]
};
self.strikeLabel.attributedText = [[NSAttributedString alloc] initWithString:strike attributes:attr];
self.strikeLabel.hidden = NO;
} else {
self.strikeLabel.attributedText = nil;
self.strikeLabel.hidden = YES;
}
}
- (void)applySelected:(BOOL)selected animated:(BOOL)animated {
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;
2025-12-17 19:45:39 +08:00
self.selectedImageView.alpha = selected ? 1.0 : 0.0;
2025-12-17 19:08:44 +08:00
};
if (animated) {
2025-12-17 19:45:39 +08:00
self.selectedImageView.hidden = NO;
[UIView animateWithDuration:0.18 animations:changes completion:^(BOOL finished) {
self.selectedImageView.hidden = !selected;
}];
2025-12-17 19:08:44 +08:00
} else {
changes();
2025-12-17 19:45:39 +08:00
self.selectedImageView.hidden = !selected;
2025-12-17 19:08:44 +08:00
}
}
- (UIView *)cardView {
if (!_cardView) {
_cardView = [[UIView alloc] init];
_cardView.backgroundColor = [UIColor colorWithWhite:1 alpha:0.96];
_cardView.layer.cornerRadius = 20;
_cardView.layer.borderWidth = 1.0;
_cardView.layer.borderColor = [[UIColor blackColor] colorWithAlphaComponent:0.12].CGColor;
}
return _cardView;
}
- (UILabel *)titleLabel {
if (!_titleLabel) {
_titleLabel = [[UILabel alloc] init];
_titleLabel.font = [UIFont systemFontOfSize:13 weight:UIFontWeightSemibold];
_titleLabel.numberOfLines = 2;
_titleLabel.textColor = [UIColor colorWithHex:0x1B1F1A];
}
return _titleLabel;
}
- (UILabel *)priceLabel {
if (!_priceLabel) {
_priceLabel = [[UILabel alloc] init];
_priceLabel.font = [UIFont systemFontOfSize:20 weight:UIFontWeightBold];
_priceLabel.textColor = [UIColor colorWithHex:0x1B1F1A];
}
return _priceLabel;
}
- (UILabel *)strikeLabel {
if (!_strikeLabel) {
_strikeLabel = [[UILabel alloc] init];
_strikeLabel.textColor = [UIColor colorWithHex:0xCCCCCC];
_strikeLabel.hidden = YES;
}
return _strikeLabel;
}
2025-12-17 19:45:39 +08:00
- (UIImageView *)selectedImageView {
if (!_selectedImageView) {
_selectedImageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"buy_sel_icon"]];
_selectedImageView.contentMode = UIViewContentModeScaleAspectFit;
_selectedImageView.hidden = YES;
_selectedImageView.alpha = 0.0;
2025-12-17 19:08:44 +08:00
}
2025-12-17 19:45:39 +08:00
return _selectedImageView;
2025-12-17 19:08:44 +08:00
}
@end