-
Notifications
You must be signed in to change notification settings - Fork 1.3k
/
Copy pathShopGoodsCCell.m
138 lines (109 loc) · 4.83 KB
/
ShopGoodsCCell.m
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
135
136
137
138
//
// ShopGoodsCCell.m
// Coding_iOS
//
// Created by liaoyp on 15/11/20.
// Copyright © 2015年 Coding. All rights reserved.
//
#import "ShopGoodsCCell.h"
#import "ShopGoods.h"
#define FONT(F) [UIFont systemFontOfSize:F]
@implementation ShopGoodsCCell
- (instancetype)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self) {
self.clipsToBounds = YES;
self.backgroundColor = [UIColor whiteColor];
[self setUpContentView];
}
return self;
}
- (void)setUpContentView{
UIView *superView = self.contentView;
_coverView = [[YLImageView alloc] initWithFrame:CGRectZero];
_coverView.backgroundColor = [UIColor colorWithHexString:@"0xe5e5e5"];
_coverView.contentMode = UIViewContentModeScaleAspectFill;
_coverView.layer.masksToBounds =YES;
[superView addSubview:_coverView];
_titleLabel = [[UILabel alloc] initWithFrame:CGRectZero];
_titleLabel.font = FONT(14);
_titleLabel.backgroundColor = [UIColor clearColor];
_titleLabel.textColor = kColor222;
[superView addSubview:_titleLabel];
_codingCoinView = [UIButton buttonWithType:UIButtonTypeCustom];
_codingCoinView.userInteractionEnabled = NO;
_codingCoinView.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;
[_codingCoinView setImage:[UIImage imageNamed:@"shop_coding_coin_icon"] forState:UIControlStateNormal];
[_codingCoinView setTitle:@" 码币 " forState:UIControlStateNormal];
[_codingCoinView setTitleColor:kColorDark7 forState:UIControlStateNormal];
[_codingCoinView.titleLabel setFont:[UIFont systemFontOfSize:14]];
[superView addSubview:_codingCoinView];
_exchangeIconView = [UIImageView new];
_exchangeIconView.contentMode = UIViewContentModeScaleAspectFill;
_exchangeIconView.clipsToBounds = YES;
_exchangeIconView.backgroundColor = [UIColor clearColor];
_exchangeIconView.image = [UIImage imageNamed:@"shop_exchange_icon"];
[superView addSubview:_exchangeIconView];
_priceLabel = [UILabel labelWithFont:[UIFont systemFontOfSize:18] textColor:kColorBrandOrange];
[superView addSubview:_priceLabel];
_countLabel = [UILabel labelWithFont:[UIFont systemFontOfSize:12] textColor:kColorDark7];
[superView addSubview:_countLabel];
float _coverViewHeight = self.frame.size.width * (176.0/284.0);
NSLog(@"_coverViewHeight %lf",_coverViewHeight);
[_coverView mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.offset(kPaddingLeftWidth);
make.centerY.equalTo(superView);
make.size.mas_equalTo(CGSizeMake(80, 80));
}];
[_titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.equalTo(_coverView);
make.left.equalTo(_coverView.mas_right).offset(20);
make.right.equalTo(superView.mas_right).offset(-kPaddingLeftWidth);
}];
[_codingCoinView mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.equalTo(_titleLabel);
make.centerY.equalTo(_coverView);
}];
[_exchangeIconView mas_makeConstraints:^(MASConstraintMaker *make) {
make.right.equalTo(superView).offset(-kPaddingLeftWidth);
make.centerY.equalTo(_countLabel);
}];
[_priceLabel mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.equalTo(_titleLabel);
make.bottom.equalTo(_coverView);
}];
[_countLabel mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.equalTo(_priceLabel.mas_right).offset(10);
make.bottom.equalTo(_priceLabel);
}];
}
- (void)configViewWithModel:(ShopGoods *)model
{
[super configViewWithModel:model];
_titleLabel.text = [model.name componentsSeparatedByCharactersInSet:[NSCharacterSet characterSetWithCharactersInString:@"¥¥"]].firstObject;
NSString *points_cost = [NSString stringWithFormat:@" %@ 码币", model.points_cost];
[_codingCoinView setTitle:points_cost forState:UIControlStateNormal];
CGFloat price = model.points_cost.floatValue * 50;
if (price - ((int)price) < .1) {
_priceLabel.text = [NSString stringWithFormat:@"¥%.0f", price];
}else{
_priceLabel.text = [NSString stringWithFormat:@"¥%.1f", price];
}
_countLabel.text = [NSString stringWithFormat:@"销量:%@", model.count];
[self showExchangeIcon:model.exchangeable];
[_coverView sd_setImageWithURL:[model.image urlImageWithCodePathResize:kScreen_Width] placeholderImage:nil];
}
- (void)showExchangeIcon:(BOOL)_isCanExchangeIcon
{
_exchangeIconView.hidden = !_isCanExchangeIcon;
// if (_isCanExchangeIcon) {
// UIImage *image = [UIImage imageNamed:@"shop_exchange_icon"];
// _exchangeIconView.image = image;
// }else
// {
// UIImage *image = [UIImage imageNamed:@"shop_unexchange_icon"];
// _exchangeIconView.image =image;
// }
}
@end