CNLiveBindingManageCell.m
5.43 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
//
// CNLiveBindingManageCell.m
// CNLiveNetAdd
//
// Created by CNLive-zxw on 2019/9/10.
// Copyright © 2019 cnlive. All rights reserved.
//
#import "CNLiveBindingManageCell.h"
#import <Masonry/Masonry.h>
#import "CNLiveBindingManageModel.h"
#import "CNLiveBindingManageRequest.h"
@interface CNLiveBindingManageCell()
@property (nonatomic, strong) UIImageView *icon;
@property (nonatomic, strong) UILabel *title;
@property (nonatomic, strong) UILabel *desc;
@property (nonatomic, strong) UIButton *manage;
@property (nonatomic, strong) UIView *line;
@end
@implementation CNLiveBindingManageCell
static NSInteger const margin = 15;
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
if (self) {
self.contentView.backgroundColor = [UIColor whiteColor];
[self createSubViews];
}
return self;
}
- (void)setModel:(CNBindingManageModel *)model{
_model = model;
_icon.image = [UIImage imageNamed:model.image];
_title.text = model.title;
_desc.text = model.desc;
if([model.isBinding isEqualToString:@"1"]){
_manage.backgroundColor = RGBOF(0xd9d9d9);
[_manage setTitle:@"已绑定" forState:UIControlStateNormal];
}else{
_manage.backgroundColor = RGBOF(0x23d41e);
[_manage setTitle:@"未绑定" forState:UIControlStateNormal];
}
}
#pragma mark - setupUI
- (void)createSubViews {
[self.contentView addSubview:self.icon];
[self.contentView addSubview:self.title];
[self.contentView addSubview:self.desc];
[self.contentView addSubview:self.manage];
[self.contentView addSubview:self.line];
}
- (void)layoutSubviews {
[self.icon mas_makeConstraints:^(MASConstraintMaker *make) {
make.centerY.equalTo(self.contentView);
make.left.equalTo(self.contentView).offset(margin);
make.width.mas_equalTo(50);
make.height.mas_equalTo(50);
}];
[self.manage mas_makeConstraints:^(MASConstraintMaker *make) {
make.centerY.equalTo(self.contentView);
make.right.equalTo(self.contentView.mas_right).offset(-margin);
make.width.mas_equalTo(70);
make.height.mas_equalTo(30);
}];
[self.title mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.equalTo(self.icon.mas_top);
make.left.equalTo(self.icon.mas_right).offset(margin);
make.right.equalTo(self.manage.mas_left).offset(-margin);
make.height.mas_equalTo(25);
}];
[self.desc mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.equalTo(self.title.mas_bottom);
make.left.equalTo(self.title.mas_left);
make.right.equalTo(self.title.mas_right);
make.height.mas_equalTo(25);
}];
[self.line mas_makeConstraints:^(MASConstraintMaker *make) {
make.bottom.equalTo(self.contentView.mas_bottom).offset(-0.5);
make.left.equalTo(self.contentView.mas_left);
make.right.equalTo(self.contentView.mas_right);
make.height.mas_equalTo(0.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
}
#pragma mark - Lazy Loading
- (UIImageView *)icon {
if (!_icon) {
_icon = [[UIImageView alloc] init];
_icon.contentMode = UIViewContentModeScaleAspectFill;
_icon.layer.cornerRadius = 25;
_icon.layer.masksToBounds = YES;
}
return _icon;
}
- (UILabel *)title {
if (!_title) {
_title = [[UILabel alloc] init];
_title.textColor = RGBOF(0x333333);
_title.font = UIFontCNMake(16);//[UIFont fontWithName:@"PingFangSC-Regular" size:15];
_title.numberOfLines = 0;
}
return _title;
}
- (UILabel *)desc {
if (!_desc) {
_desc = [[UILabel alloc] init];
_desc.textColor = RGBOF(0x999999);
_desc.font = UIFontCNMake(12);//[UIFont fontWithName:@"PingFangSC-Regular" size:15];
_desc.numberOfLines = 0;
}
return _desc;
}
- (UIButton *)manage {
if (!_manage) {
_manage = [UIButton buttonWithType:UIButtonTypeCustom];
_manage.backgroundColor = RGBOF(0xd9d9d9);
[_manage setTitle:@"已绑定" forState:UIControlStateNormal];
[_manage setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
_manage.titleLabel.font = UIFontCNMake(14);
_manage.layer.cornerRadius = 15;
_manage.layer.masksToBounds = YES;
[_manage addTarget:self action:@selector(manageDidClicked:) forControlEvents:UIControlEventTouchUpInside];
}
return _manage;
}
- (UIView *)line {
if (!_line) {
_line = [[UIView alloc] init];
_line.backgroundColor = RGBOF(0xeeeeee);
}
return _line;
}
#pragma mark - Action
- (void)manageDidClicked:(UIButton *)btn{
if([self.model.thirdPartyPlat isEqualToString:@"10"]){
return;
}
if(![CNLiveNetworking isNetworking]){
[QMUITips showError:@"无法连接网络" inView:AppKeyWindow hideAfterDelay:1.5];
return ;
}
btn.userInteractionEnabled = NO;
if (self.delegate && [self.delegate respondsToSelector:@selector(clickedBindingButton:isBinding:)]) {
[self.delegate clickedBindingButton:self isBinding:![self.model.isBinding isEqualToString:@"1"]];
btn.userInteractionEnabled = YES;
}
}
@end