处理svip
This commit is contained in:
130
keyBoard/Class/Pay/V/KBSvipSubscribeCell.m
Normal file
130
keyBoard/Class/Pay/V/KBSvipSubscribeCell.m
Normal file
@@ -0,0 +1,130 @@
|
||||
//
|
||||
// KBSvipSubscribeCell.m
|
||||
// keyBoard
|
||||
//
|
||||
// SVIP 订阅选项样式,横向排列,选中时绿色边框
|
||||
//
|
||||
|
||||
#import "KBSvipSubscribeCell.h"
|
||||
|
||||
@interface KBSvipSubscribeCell ()
|
||||
@property (nonatomic, strong) UIView *cardView; // 白色卡片背景
|
||||
@property (nonatomic, strong) UILabel *titleLabel; // "1 Week" / "1 Month" / "1 Year"
|
||||
@property (nonatomic, strong) UILabel *priceLabel; // "$6.90"
|
||||
@property (nonatomic, strong) UILabel *strikeLabel; // 删除线原价
|
||||
@end
|
||||
|
||||
@implementation KBSvipSubscribeCell
|
||||
|
||||
- (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.titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
|
||||
make.centerX.equalTo(self.cardView);
|
||||
make.top.equalTo(self.cardView).offset(12);
|
||||
}];
|
||||
[self.priceLabel mas_makeConstraints:^(MASConstraintMaker *make) {
|
||||
make.centerX.equalTo(self.cardView);
|
||||
make.top.equalTo(self.titleLabel.mas_bottom).offset(8);
|
||||
}];
|
||||
[self.strikeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
|
||||
make.centerX.equalTo(self.cardView);
|
||||
make.top.equalTo(self.priceLabel.mas_bottom).offset(4);
|
||||
}];
|
||||
|
||||
// 基于 CALayer 的边框
|
||||
self.cardView.layer.borderWidth = 1.5;
|
||||
self.cardView.layer.borderColor = [UIColor colorWithWhite:0.9 alpha:1.0].CGColor;
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
- (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 : @"1 Month";
|
||||
self.priceLabel.text = price.length ? price : @"$6.90";
|
||||
self.strikeLabel.hidden = (strike.length == 0);
|
||||
if (strike.length) {
|
||||
NSDictionary *attr = @{
|
||||
NSStrikethroughStyleAttributeName: @(NSUnderlineStyleSingle),
|
||||
NSForegroundColorAttributeName: [UIColor colorWithHex:0x999999]
|
||||
};
|
||||
self.strikeLabel.attributedText = [[NSAttributedString alloc] initWithString:strike attributes:attr];
|
||||
}
|
||||
}
|
||||
|
||||
- (void)applySelected:(BOOL)selected animated:(BOOL)animated {
|
||||
CGColorRef color = (selected ? [UIColor colorWithHex:KBColorValue].CGColor : [UIColor colorWithWhite:0.9 alpha:1.0].CGColor);
|
||||
UIColor *bgColor = selected ? [UIColor colorWithHex:0xE8FFF6] : [UIColor whiteColor];
|
||||
void (^changes)(void) = ^{
|
||||
self.cardView.layer.borderColor = color;
|
||||
self.cardView.backgroundColor = bgColor;
|
||||
};
|
||||
if (animated) {
|
||||
[UIView animateWithDuration:0.2 animations:changes];
|
||||
} else {
|
||||
changes();
|
||||
}
|
||||
}
|
||||
|
||||
#pragma mark - Lazy
|
||||
- (UIView *)cardView {
|
||||
if (!_cardView) {
|
||||
_cardView = [UIView new];
|
||||
_cardView.backgroundColor = [UIColor whiteColor];
|
||||
_cardView.layer.cornerRadius = 12;
|
||||
_cardView.clipsToBounds = YES;
|
||||
}
|
||||
return _cardView;
|
||||
}
|
||||
|
||||
- (UILabel *)titleLabel {
|
||||
if (!_titleLabel) {
|
||||
_titleLabel = [UILabel new];
|
||||
_titleLabel.text = @"1 Month";
|
||||
_titleLabel.textColor = [UIColor colorWithHex:KBBlackValue];
|
||||
_titleLabel.font = [KBFont medium:13];
|
||||
}
|
||||
return _titleLabel;
|
||||
}
|
||||
|
||||
- (UILabel *)priceLabel {
|
||||
if (!_priceLabel) {
|
||||
_priceLabel = [UILabel new];
|
||||
_priceLabel.text = @"$6.90";
|
||||
_priceLabel.textColor = [UIColor colorWithHex:KBBlackValue];
|
||||
_priceLabel.font = [KBFont bold:22];
|
||||
}
|
||||
return _priceLabel;
|
||||
}
|
||||
|
||||
- (UILabel *)strikeLabel {
|
||||
if (!_strikeLabel) {
|
||||
_strikeLabel = [UILabel new];
|
||||
_strikeLabel.text = @"$4.49";
|
||||
_strikeLabel.font = [KBFont regular:12];
|
||||
_strikeLabel.textColor = [UIColor colorWithHex:0x999999];
|
||||
}
|
||||
return _strikeLabel;
|
||||
}
|
||||
|
||||
@end
|
||||
Reference in New Issue
Block a user