CNLiveUserInfoCell.m
7.5 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
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
//
// CNLiveMineController.m
// CNLiveMineModule
//
// Created by 153993236@qq.com on 11/12/2019.
// Copyright (c) 2019 153993236@qq.com. All rights reserved.
//
#import "CNLiveUserInfoCell.h"
#import <Masonry/Masonry.h>
#import <SDWebImage/SDWebImage.h>
#import "CNLiveUserInfoModel.h"
@interface CNLiveUserInfoCell()
@property (nonatomic, strong) UIView *line;
@property (nonatomic, strong) UILabel *title;
@property (nonatomic, strong) UILabel *content;
@property (nonatomic, strong) UIImageView *front;
@property (nonatomic, strong) UIImageView *pic;
@end
@implementation CNLiveUserInfoCell
static const NSInteger margin = 12;
- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
if (self) {
self.contentView.backgroundColor = [UIColor whiteColor];
[self.contentView addSubview:self.line];
[self.contentView addSubview:self.title];
[self.contentView addSubview:self.content];
[self.contentView addSubview:self.front];
[self.contentView addSubview:self.pic];
}
return self;
}
- (void)setImage:(UIImage *)image{
_image = image;
if(self.model.dataType == CNLiveUserInfoDataTypeHead){
_pic.image = image;
}
}
- (void)setModel:(CNLiveUserInfoModel *)model{
_model = model;
_title.text = model.title;
_content.text = model.content;
if(model.dataType == CNLiveUserInfoDataTypeHead){
_pic.backgroundColor = [UIColor whiteColor];
_pic.contentMode = UIViewContentModeScaleToFill;
_pic.layer.masksToBounds = YES;
_pic.layer.cornerRadius = 5.0;
UIImage *xw_image = [self xw_getImageName:@"default_avatar_f" bundleName:@"CNLiveMineModule" targetClass:[CNLiveUserInfoCell class]];
[_pic sd_setImageWithURL:[NSURL URLWithString:model.content] placeholderImage:xw_image];
}else if (model.dataType == CNLiveUserInfoDataTypeNickname){
}else if (model.dataType == CNLiveUserInfoDataTypeGender){
if([model.content isEqualToString:@"0"]){
_content.text = @"男";
}else if([model.content isEqualToString:@"1"]){
_content.text = @"女";
}else{
_content.text = @"未知";
}
}else if (model.dataType == CNLiveUserInfoDataTypeCode){
_pic.contentMode = UIViewContentModeCenter;
_pic.layer.masksToBounds = NO;
_pic.layer.cornerRadius = 0.0;
UIImage *xw_image = [self xw_getImageName:@"mine_info_qrcode" bundleName:@"CNLiveMineModule" targetClass:[CNLiveUserInfoCell class]];
_pic.image = xw_image;
}else if (model.dataType == CNLiveUserInfoDataTypeAddress){
}else if (model.dataType == CNLiveUserInfoDataTypeIntroduction){
}
[self xw_layoutSubviews];
}
- (void)xw_layoutSubviews{
CGFloat line_margin = self.model.lineHeight >= 5?0:margin;
[_line mas_updateConstraints:^(MASConstraintMaker *make) {
make.left.equalTo(self.contentView.mas_left).with.offset(line_margin);
make.right.equalTo(self.contentView.mas_right).with.offset(-line_margin);
make.bottom.equalTo(self.contentView.mas_bottom).with.offset(0);
make.height.offset(self.model.lineHeight);
}];
[_title mas_updateConstraints:^(MASConstraintMaker *make) {
make.left.equalTo(self.contentView.mas_left).with.offset(margin);
make.top.equalTo(self.contentView.mas_top).with.offset(0);
make.height.offset(self.model.height-self.model.lineHeight);
}];
[_front mas_updateConstraints:^(MASConstraintMaker *make) {
make.right.equalTo(self.contentView.mas_right).with.offset(-margin);
make.top.equalTo(self.title.mas_top).with.offset(0);
make.width.with.offset(margin);
make.height.equalTo(self.title.mas_height);
}];
switch (self.model.layoutType) {
case CNLiveUserInfoLayoutTypeText:
{
_content.hidden = NO;
_pic.hidden = YES;
[_content mas_updateConstraints:^(MASConstraintMaker *make) {
make.top.equalTo(self.title.mas_top).with.offset(0);
make.left.equalTo(self.title.mas_right).with.offset(margin);
make.right.equalTo(self.front.mas_left).with.offset(-margin);
make.height.equalTo(self.title.mas_height);
}];
}
break;
case CNLiveUserInfoLayoutTypeImage:
{
CGFloat height = self.model.height-self.model.lineHeight-2*margin;
_content.hidden = YES;
_pic.hidden = NO;
[_pic mas_updateConstraints:^(MASConstraintMaker *make) {
make.top.equalTo(self.contentView.mas_top).with.offset(margin);
make.right.equalTo(self.front.mas_left).with.offset(-margin);
make.width.height.offset(height);
}];
}
break;
default:
{
_content.hidden = YES;
_pic.hidden = YES;
}
break;
}
}
- (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 - 懒加载
- (UIView *)line {
if (!_line) {
_line = [[UIView alloc] init];
_line.backgroundColor = [UIColor colorWithRed:235/255.0 green:235/255.0 blue:235/255.0 alpha:1.0];
}
return _line;
}
- (UILabel *)title {
if (!_title) {
_title = [[UILabel alloc] init];
_title.numberOfLines = 1;
_title.textColor = [UIColor colorWithRed:51/255.0 green:51/255.0 blue:51/255.0 alpha:1.0];
_title.font = [UIFont systemFontOfSize:16];
}
return _title;
}
- (UILabel *)content {
if (!_content) {
_content = [[UILabel alloc] init];
_content.numberOfLines = 1;
_content.lineBreakMode = NSLineBreakByTruncatingTail;
_content.textColor = [UIColor colorWithRed:102/255.0 green:102/255.0 blue:102/255.0 alpha:1.0];
_content.font = [UIFont systemFontOfSize:14];
}
return _content;
}
- (UIImageView *)front {
if (!_front) {
_front = [[UIImageView alloc] init];
UIImage *xw_image = [self xw_getImageName:@"mine_info_front" bundleName:@"CNLiveMineModule" targetClass:[CNLiveUserInfoCell class]];
_front.image = xw_image;
_front.contentMode = UIViewContentModeCenter;
}
return _front;
}
- (UIImageView *)pic {
if (!_pic) {
_pic = [[UIImageView alloc] init];
}
return _pic;
}
#pragma mark - 响应方法
- (void)switchChanged:(UISwitch *)sw{
}
/**
* 创建图片
*
* @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