// // KBSkinCardCell.m // keyBoard // #import "KBSkinCardCell.h" #import "KBMoneyBtn.h" @interface KBSkinCardCell () @property (nonatomic, strong) UIImageView *coverView; // 封面 @property (nonatomic, strong) UILabel *titleLabel; // 标题 @property (nonatomic, strong) KBMoneyBtn *priceBtn; // 价格 @end @implementation KBSkinCardCell - (instancetype)initWithFrame:(CGRect)frame { if (self = [super initWithFrame:frame]) { self.contentView.backgroundColor = [UIColor colorWithHex:0xF8F8F8]; self.contentView.layer.cornerRadius = 12; self.contentView.layer.masksToBounds = YES; self.contentView.layer.shadowColor = [UIColor colorWithWhite:0 alpha:0.06].CGColor; self.contentView.layer.shadowOpacity = 1; self.contentView.layer.shadowOffset = CGSizeMake(0, 2); [self.contentView addSubview:self.coverView]; [self.contentView addSubview:self.titleLabel]; [self.contentView addSubview:self.priceBtn]; [self.coverView mas_makeConstraints:^(MASConstraintMaker *make) { make.top.left.right.equalTo(self.contentView); make.height.mas_equalTo(KBFit(126)); }]; [self.titleLabel mas_makeConstraints:^(MASConstraintMaker *make) { make.left.equalTo(self.contentView).offset(12); make.right.equalTo(self.contentView).offset(-12); make.top.equalTo(self.coverView.mas_bottom).offset(KBFit(8)); make.height.mas_equalTo(KBFit(20)); }]; [self.priceBtn mas_makeConstraints:^(MASConstraintMaker *make) { make.left.equalTo(self.titleLabel); make.bottom.equalTo(self.contentView).offset(-12); }]; } return self; } - (void)configWithTitle:(NSString *)title imageURL:(NSString *)url price:(NSString *)price { self.titleLabel.text = title.length ? title : @"Dopamine"; [self.priceBtn setTitle:@"20" forState:UIControlStateNormal]; // 简化:本地展示占位色,无网络图 self.coverView.backgroundColor = [UIColor colorWithWhite:0.92 alpha:1.0]; } #pragma mark - Lazy - (UIImageView *)coverView { if (!_coverView) { _coverView = [[UIImageView alloc] init]; _coverView.contentMode = UIViewContentModeScaleAspectFill; _coverView.clipsToBounds = YES; _coverView.backgroundColor = [UIColor colorWithWhite:0.94 alpha:1.0]; } return _coverView; } - (UILabel *)titleLabel { if (!_titleLabel) { _titleLabel = [[UILabel alloc] init]; _titleLabel.font = [UIFont systemFontOfSize:15 weight:UIFontWeightSemibold]; _titleLabel.textColor = [UIColor colorWithHex:KBBlackValue]; } return _titleLabel; } - (KBMoneyBtn *)priceBtn { if (!_priceBtn) { _priceBtn = [KBMoneyBtn buttonWithType:UIButtonTypeCustom]; } return _priceBtn; } @end