87 lines
2.9 KiB
Objective-C
87 lines
2.9 KiB
Objective-C
//
|
|
// KBSkinCardCell.m
|
|
// keyBoard
|
|
//
|
|
|
|
#import "KBSkinCardCell.h"
|
|
|
|
@interface KBSkinCardCell ()
|
|
@property (nonatomic, strong) UIImageView *coverView; // 封面
|
|
@property (nonatomic, strong) UILabel *titleLabel; // 标题
|
|
@property (nonatomic, strong) UILabel *priceLabel; // 价格
|
|
@end
|
|
|
|
@implementation KBSkinCardCell
|
|
|
|
- (instancetype)initWithFrame:(CGRect)frame {
|
|
if (self = [super initWithFrame:frame]) {
|
|
self.contentView.backgroundColor = [UIColor whiteColor];
|
|
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.priceLabel];
|
|
|
|
[self.coverView mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
make.top.left.right.equalTo(self.contentView);
|
|
make.height.equalTo(self.contentView.mas_width).multipliedBy(0.75); // 4:3
|
|
}];
|
|
|
|
[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(8);
|
|
}];
|
|
|
|
[self.priceLabel mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
make.left.equalTo(self.titleLabel);
|
|
make.bottom.equalTo(self.contentView).offset(-10);
|
|
}];
|
|
}
|
|
return self;
|
|
}
|
|
|
|
- (void)configWithTitle:(NSString *)title imageURL:(NSString *)url price:(NSString *)price {
|
|
self.titleLabel.text = title.length ? title : @"Dopamine";
|
|
self.priceLabel.text = price.length ? price : @"20";
|
|
// 简化:本地展示占位色,无网络图
|
|
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:0x1B1F1A];
|
|
}
|
|
return _titleLabel;
|
|
}
|
|
|
|
- (UILabel *)priceLabel {
|
|
if (!_priceLabel) {
|
|
_priceLabel = [[UILabel alloc] init];
|
|
_priceLabel.font = [UIFont systemFontOfSize:14];
|
|
_priceLabel.textColor = [UIColor colorWithRed:0.15 green:0.72 blue:0.62 alpha:1.0];
|
|
}
|
|
return _priceLabel;
|
|
}
|
|
|
|
@end
|
|
|