164 lines
5.8 KiB
Objective-C
164 lines
5.8 KiB
Objective-C
//
|
|
// 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;
|
|
@property (nonatomic, strong) UIView *checkBadge;
|
|
@property (nonatomic, strong) UILabel *checkLabel;
|
|
@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];
|
|
[self.cardView addSubview:self.checkBadge];
|
|
[self.checkBadge addSubview:self.checkLabel];
|
|
|
|
[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) {
|
|
make.top.equalTo(self.cardView.mas_top).offset(4);
|
|
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);
|
|
}];
|
|
|
|
[self.checkBadge 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);
|
|
}];
|
|
}
|
|
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;
|
|
self.checkBadge.backgroundColor = selected ? [UIColor colorWithHex:0x02BEAC] : [[UIColor blackColor] colorWithAlphaComponent:0.15];
|
|
self.checkLabel.textColor = [UIColor whiteColor];
|
|
};
|
|
if (animated) {
|
|
[UIView animateWithDuration:0.18 animations:changes];
|
|
} else {
|
|
changes();
|
|
}
|
|
}
|
|
|
|
- (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;
|
|
}
|
|
|
|
- (UIView *)checkBadge {
|
|
if (!_checkBadge) {
|
|
_checkBadge = [[UIView alloc] init];
|
|
_checkBadge.layer.cornerRadius = 10;
|
|
_checkBadge.backgroundColor = [[UIColor blackColor] colorWithAlphaComponent:0.15];
|
|
}
|
|
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;
|
|
}
|
|
@end
|