YHL_HotSaleTableViewCell.m
4.31 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
//
// YHL_HotSaleTableViewCell.m
// YohoLive
//
// Created by 盖剑秋 on 2016/11/14.
// Copyright © 2016年 YOHO!. All rights reserved.
//
#import "YHL_HotSaleTableViewCell.h"
#import "NSString+LIVE.h"
#import "UIImageView+WebCache.h"
@implementation YHL_HotSaleTableViewCell
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
[self.contentView addSubview:self.productImageView];
[self.contentView addSubview:self.productNameLable];
[self.contentView addSubview:self.salePriceLable];
[self.contentView addSubview:self.originalPriceLable];
[self layoutContentSubviews];
UIView *line = [UIView new];
line.backgroundColor = [UIColor lightGrayColor];
[self.contentView addSubview:line];
[line mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.and.bottom.and.right.mas_equalTo(0);
make.height.mas_equalTo(0.5);
}];
}
return self;
}
- (void)layoutContentSubviews
{
[self.productImageView mas_makeConstraints:^(MASConstraintMaker *make) {
make.size.mas_equalTo(CGSizeMake(76, 102));
make.top.mas_equalTo(10);
make.left.mas_equalTo(15);
}];
[self.productNameLable mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.equalTo(self.productImageView.mas_right).offset(15);
make.right.mas_equalTo(-10);
make.top.mas_equalTo(15);
}];
[self.salePriceLable mas_makeConstraints:^(MASConstraintMaker *make) {
make.bottom.mas_equalTo(-25);
make.left.equalTo(self.productImageView.mas_right).offset(15);
}];
[self.originalPriceLable mas_makeConstraints:^(MASConstraintMaker *make) {
make.bottom.mas_equalTo(-25);
make.left.equalTo(self.salePriceLable.mas_right).offset(10);
}];
}
- (void)bindModel:(YHL_Product *)model
{
if (![model isKindOfClass:[YHL_Product class]]) {
return;
}
_currentProduct = model;
self.productNameLable.text = model.productName;
NSString *marketPrice = model.marketPrice;//吊牌价
NSString *salesPrice = model.salesPrice;//当前价格
self.salePriceLable.text = [NSString stringWithFormat:@"¥%@",salesPrice];
if (salesPrice.floatValue != marketPrice.floatValue) {
self.originalPriceLable.hidden = NO;
NSAttributedString *originalAttString = [[NSAttributedString alloc] initWithString:[NSString stringWithFormat:@"¥%@",model.marketPrice] attributes:@{NSStrikethroughStyleAttributeName:@(NSUnderlineStyleSingle)}];
self.originalPriceLable.attributedText = originalAttString;
} else {
self.originalPriceLable.hidden = YES;
}
NSString *picUrlString = [model.picUrl yhl_splitUrlWithWidth:@(CGRectGetWidth(self.productImageView.bounds)*kScreenScale).stringValue height:@(CGRectGetHeight(self.productImageView.bounds)*kScreenScale).stringValue];
[self.productImageView sd_setImageWithURL:[NSURL URLWithString:picUrlString]];
}
+ (CGFloat)cellForHeight
{
return 122.0f;
}
- (UIImageView *)productImageView
{
if (!_productImageView) {
_productImageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 76, 102)];//76 * 102
_productImageView.userInteractionEnabled = YES;
_productImageView.backgroundColor = [UIColor lightGrayColor];
}
return _productImageView;
}
- (UILabel *)productNameLable
{
if (!_productNameLable) {
_productNameLable = [[UILabel alloc] init];
_productNameLable.numberOfLines = 2;
_productNameLable.font = [UIFont systemFontOfSize:11];
_productNameLable.textColor = [UIColor blackColor];
}
return _productNameLable;
}
- (UILabel *)salePriceLable
{
if (!_salePriceLable) {
_salePriceLable = [[UILabel alloc] init];
_salePriceLable.font = [UIFont systemFontOfSize:17];
_salePriceLable.textColor = [UIColor redColor];
}
return _salePriceLable;
}
- (UILabel *)originalPriceLable
{
if (!_originalPriceLable) {
_originalPriceLable = [[UILabel alloc] init];
_originalPriceLable.font = [UIFont systemFontOfSize:9];
_originalPriceLable.textColor = [UIColor lightGrayColor];
}
return _originalPriceLable;
}
@end