CNLiveNewsThreePicTableViewCell.m
6.83 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
163
164
165
166
167
168
169
170
171
172
173
174
//
// CNLiveNewsThreePicTableViewCell.m
// CNLiveScioLive
//
// Created by CNLive-zxw on 2018/9/21.
// Copyright © 2018年 CNLive. All rights reserved.
//
#import "CNLiveNewsThreePicTableViewCell.h"
#import "CNHomeModel.h"
@interface CNLiveNewsThreePicTableViewCell()
@property (nonatomic, strong) UIImageView *backgroundImage;//背景图
@property (nonatomic, strong) UIImageView *picImage;//一张图片 三张图中间一张
@property (nonatomic, strong) UILabel *titleLabel;
@property (nonatomic, strong) UILabel *timeLabel;
@property (nonatomic, strong) UIImageView *rightImage;//三张图 右
@property (nonatomic, strong) UIImageView *leftImage;//三张图 左
@property (nonatomic, strong) UILabel *projectLabel;//专题
@end
@implementation CNLiveNewsThreePicTableViewCell
//static const NSInteger margin = 10;
- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
if (self) {
self.contentView.backgroundColor = HEXCOLOR(0xebebeb);
_backgroundImage = [[UIImageView alloc] init];
_backgroundImage.contentMode = UIViewContentModeCenter;
_backgroundImage.layer.masksToBounds = YES;
_backgroundImage.layer.cornerRadius = 2.0;
_backgroundImage.backgroundColor = [UIColor whiteColor];
[self.contentView addSubview:_backgroundImage];
_picImage = [[UIImageView alloc] init];
_picImage.contentMode = UIViewContentModeScaleAspectFill;
_picImage.layer.masksToBounds = YES;
_picImage.image = [UIImage imageNamed:@"placeholder"];
[self.contentView addSubview:_picImage];
_titleLabel = [[UILabel alloc] init];
_titleLabel.numberOfLines = 2;
_titleLabel.lineBreakMode = NSLineBreakByTruncatingTail;
_titleLabel.textColor = HEXCOLOR(0x333333);
_titleLabel.font = [UIFont systemFontOfSize:16];
[self.contentView addSubview:_titleLabel];
_timeLabel = [[UILabel alloc] init];
_timeLabel.numberOfLines = 1;
_timeLabel.textColor = HEXCOLOR(0xbbbbbb);
_timeLabel.font = [UIFont systemFontOfSize:14];
[self.contentView addSubview:_timeLabel];
_rightImage = [[UIImageView alloc] init];
_rightImage.contentMode = UIViewContentModeScaleAspectFill;
_rightImage.layer.masksToBounds = YES;
_rightImage.image = [UIImage imageNamed:@"placeholder"];
[self.contentView addSubview:_rightImage];
_leftImage = [[UIImageView alloc] init];
_leftImage.contentMode = UIViewContentModeScaleAspectFill;
_leftImage.layer.masksToBounds = YES;
_leftImage.image = [UIImage imageNamed:@"placeholder"];
[self.contentView addSubview:_leftImage];
_projectLabel = [[UILabel alloc] init];
_projectLabel.numberOfLines = 1;
_projectLabel.lineBreakMode = NSLineBreakByTruncatingTail;
_projectLabel.textColor = [UIColor whiteColor];
_projectLabel.backgroundColor = Color_Blue;
_projectLabel.font = [UIFont systemFontOfSize:12];
_projectLabel.layer.masksToBounds = YES;
_projectLabel.layer.cornerRadius = 2;
[self.contentView addSubview:_projectLabel];
}
return self;
}
- (void)setModel:(CNHomeModel *)model{
_model = model;
_titleLabel.text = model.title;
_timeLabel.text = [model.createDate componentsSeparatedByString:@" "][0];
if(model.tags && ![model.tags isEqualToString:@""]){
_projectLabel.text = model.tags;
}else if(model.subjecttag && ![model.subjecttag isEqualToString:@""]){
_projectLabel.text = model.subjecttag;
}
if (model.titleColor &&![model.titleColor isEqualToString:@""]) {
_titleLabel.textColor = [UIColor colorWithHexString:model.titleColor];
}
if (model.tagsColor&&![model.tagsColor isEqualToString:@""]) {
_projectLabel.backgroundColor = [UIColor colorWithHexString:model.tagsColor];
}
[_leftImage sd_setImageWithURL:[NSURL URLWithString:model.img] placeholderImage:[UIImage imageNamed:@"placeholder"]];
[_picImage sd_setImageWithURL:[NSURL URLWithString:model.imgSmall] placeholderImage:[UIImage imageNamed:@"placeholder"]];
[_rightImage sd_setImageWithURL:[NSURL URLWithString:model.imgBig] placeholderImage:[UIImage imageNamed:@"placeholder"]];
[self layoutSubviews];
}
- (void)layoutSubviews{
[_backgroundImage mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.equalTo(self.mas_left).with.offset(10);
make.right.equalTo(self.mas_right).with.offset(-10);
make.top.equalTo(self.mas_top).with.offset(5);
make.bottom.equalTo(self.mas_bottom).with.offset(-5);
}];
CGFloat width = (MainScreenWidth - 20 - 20)/3.0;
[_titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.equalTo(self->_backgroundImage.mas_left).with.offset(10);
make.top.equalTo(self->_backgroundImage.mas_top).with.offset(5);
make.right.equalTo(self->_backgroundImage.mas_right).with.offset(-10);
make.height.offset(40);
}];
[_leftImage mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.equalTo(self->_backgroundImage.mas_left).with.offset(5);
make.top.equalTo(self->_titleLabel.mas_bottom).with.offset(5);
make.width.offset(width);
make.height.offset(width);
}];
[_picImage mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.equalTo(self->_leftImage.mas_right).with.offset(5);
make.top.equalTo(self->_titleLabel.mas_bottom).with.offset(5);
make.width.offset(width);
make.height.offset(width);
}];
[_rightImage mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.equalTo(self->_picImage.mas_right).with.offset(5);
make.top.equalTo(self->_titleLabel.mas_bottom).with.offset(5);
make.width.offset(width);
make.height.offset(width);
}];
[_timeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.equalTo(self->_backgroundImage.mas_left).with.offset(10);
make.right.equalTo(self->_backgroundImage.mas_right).with.offset(-10);
make.bottom.equalTo(self->_backgroundImage.mas_bottom).with.offset(-5);
}];
[_projectLabel mas_makeConstraints:^(MASConstraintMaker *make) {
make.right.equalTo(self->_backgroundImage.mas_right).with.offset(-10);
make.bottom.equalTo(self->_backgroundImage.mas_bottom).with.offset(-5);
}];
}
- (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
}
@end