CNLiveIntegralDetailsTableViewCell.m
5.1 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
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
//
// CNLiveIntegralDetailsTableViewCell.m
// CNLiveIntegralModule
//
// Created by CNLive-zxw on 2019/3/1.
// Copyright © 2019年 cnlive. All rights reserved.
//
#import "CNLiveIntegralDetailsTableViewCell.h"
#import "QMUIKit.h"
#import <Masonry/Masonry.h>
#import <SDWebImage/SDWebImage.h>
#import "CNLiveScoreModel.h"
@interface CNLiveIntegralDetailsTableViewCell()
@property (nonatomic, strong) UILabel *titleLabel;
@property (nonatomic, strong) UILabel *timeLabel;
@property (nonatomic, strong) QMUIButton *scoresBtn;
@property (nonatomic, strong) UIView *line;
@end
@implementation CNLiveIntegralDetailsTableViewCell
static const NSInteger margin = 15;
#pragma mark - Init
- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
if (self) {
self.contentView.backgroundColor = [UIColor whiteColor];
[self setupUI];
[self xw_layoutSubviews];
}
return self;
}
#pragma mark - UI
- (void)setupUI{
[self.contentView addSubview:self.titleLabel];
[self.contentView addSubview:self.timeLabel];
[self.contentView addSubview:self.scoresBtn];
[self.contentView addSubview:self.line];
}
- (void)xw_layoutSubviews{
[_scoresBtn mas_makeConstraints:^(MASConstraintMaker *make) {
make.centerY.equalTo(self.mas_centerY).with.offset(0);
make.right.equalTo(self.mas_right).with.offset(-margin);
}];
[_titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.equalTo(self.mas_top).with.offset(margin);
make.left.equalTo(self.mas_left).with.offset(margin);
make.right.lessThanOrEqualTo(_scoresBtn.mas_left).offset(-margin);
}];
[_timeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
make.bottom.equalTo(self.mas_bottom).with.offset(-margin);
make.left.equalTo(self.mas_left).with.offset(margin);
make.right.equalTo(_scoresBtn.mas_left).with.offset(-margin);
}];
[_line mas_makeConstraints:^(MASConstraintMaker *make) {
make.bottom.equalTo(self.mas_bottom).with.offset(-0.5);
make.left.equalTo(self.mas_left).with.offset(margin);
make.right.equalTo(self.mas_right).with.offset(0);
make.height.offset(0.5);
}];
}
#pragma mark - Data
- (void)setModel:(CNLiveScoreModel *)model{
_model = model;
_titleLabel.text = model.title;
_timeLabel.text = model.date;
[_scoresBtn setTitle:[NSString stringWithFormat:@"%@%@",[model.source isEqualToString:@"1"]?@"+":@"-",model.integral] forState:UIControlStateNormal];
}
- (void)awakeFromNib {
[super awakeFromNib];
// Initialization code
}
- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
[super setSelected:selected animated:animated];
// Configure the view for the selected state
}
#pragma mark - Lazy loading
- (UILabel *)titleLabel{
if(_titleLabel == nil){
_titleLabel = [[UILabel alloc] init];
_titleLabel.textColor = [UIColor blackColor];
_titleLabel.font = UIFontMake(17);
}
return _titleLabel;
}
- (UILabel *)timeLabel{
if(_timeLabel == nil){
_timeLabel = [[UILabel alloc] init];
_timeLabel.textColor = [UIColor colorWithRed:136/255.0 green:136/255.0 blue:136/255.0 alpha:1.0];
_timeLabel.font = UIFontMake(11);
_timeLabel.userInteractionEnabled = YES;
}
return _timeLabel;
}
- (QMUIButton *)scoresBtn{
if(_scoresBtn == nil){
_scoresBtn = [QMUIButton buttonWithType:UIButtonTypeCustom];
_scoresBtn.titleLabel.font = UIFontMake(14);
[_scoresBtn setTitleColor:[UIColor colorWithRed:249/255.0 green:171/255.0 blue:37/255.0 alpha:1.0] forState:UIControlStateNormal];
UIImage *image = [self xw_getImageName:@"mf_soccer_smallcoin" bundleName:@"CNLiveIntegralModule" targetClass:[self class]];
[_scoresBtn setImage:image forState:UIControlStateNormal];
_scoresBtn.adjustsImageWhenHighlighted = NO;
_scoresBtn.spacingBetweenImageAndTitle = 5;
_scoresBtn.imagePosition = QMUIButtonImagePositionRight;
}
return _scoresBtn;
}
- (UIView *)line{
if(_line == nil){
_line = [[UIView alloc] init];
_line.backgroundColor = [UIColor colorWithRed:235/255.0 green:235/255.0 blue:235/255.0 alpha:1.0];
}
return _line;
}
/**
* 创建图片
*
* @param imageName 图片名字
* @param bundleName 图片所在的bundle名字
* @param targetClass 类和bundle的同级目录
* @return 返回UIImage
*/
- (UIImage *)xw_getImageName:(NSString *)imageName bundleName:(NSString *)bundleName targetClass:(Class)targetClass{
NSBundle *bundle = [NSBundle bundleForClass:targetClass];
NSURL *url = [bundle URLForResource:bundleName withExtension:@"bundle"];
NSBundle *targetBundle = [NSBundle bundleWithURL:url];
UIImage *image = [UIImage imageNamed:imageName inBundle:targetBundle compatibleWithTraitCollection:nil];
return image?image:[UIImage imageNamed:imageName inBundle:[NSBundle mainBundle] compatibleWithTraitCollection:nil];
}
@end