CNLiveNotSeeCell.m
4.96 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
//
// CNLiveNotSeeCell.m
// CNLiveSettingModule
//
// Created by CNLive-zxw on 2019/4/22.
// Copyright © 2019 cnlive. All rights reserved.
//
#import "CNLiveNotSeeCell.h"
#import <SDWebImage/SDWebImage.h>
#import "QMUIKit.h"
#import <Masonry/Masonry.h>
#import "CNLiveCategory.h"
#import "CNLiveNotSeeModel.h"
@interface CNLiveNotSeeCell()
@property (nonatomic, strong) UIButton *delButton;
@property (nonatomic, strong) UIImageView *avatarImage;
@property (nonatomic, strong) UILabel *nameLabel;
@end
@implementation CNLiveNotSeeCell
static const NSInteger margin = 15;
- (instancetype)initWithFrame:(CGRect)frame {
self = [super initWithFrame:frame];
if (self) {
self.backgroundColor = [UIColor whiteColor];
[self configSubviews];
[self xw_layoutSubviews];
}
return self;
}
#pragma mark - Data
- (void)setModel:(CNLiveNotSeeModel *)model {
_model = model;
if(model.type == CNLiveNotSeeModelTypeAdd){
_avatarImage.layer.masksToBounds = NO;
_avatarImage.layer.cornerRadius = 0;
UIImage *xw_image = [self getImageWithImageName:@"privacy_plus" bundleName:@"CNLiveSettingModule" targetClass:[self class]];
[_avatarImage sd_setImageWithURL:[NSURL URLWithString:@""] placeholderImage:xw_image];
_nameLabel.text = @"";
}else if (model.type == CNLiveNotSeeModelTypeMinus){
_avatarImage.layer.masksToBounds = NO;
_avatarImage.layer.cornerRadius = 0;
UIImage *xw_image = [self getImageWithImageName:@"privacy_less" bundleName:@"CNLiveSettingModule" targetClass:[self class]];
[_avatarImage sd_setImageWithURL:[NSURL URLWithString:@""] placeholderImage:xw_image];
_nameLabel.text = @"";
}else{
_avatarImage.layer.masksToBounds = YES;
_avatarImage.layer.cornerRadius = 5;
[_avatarImage sd_setImageWithURL:[NSURL URLWithString:model.image] placeholderImage:[UIImage imageNamed:@""]];
_nameLabel.text = model.nickName;
}
if(model.type == CNLiveNotSeeModelTypeDefault && [model.isEdit isEqualToString:@"1"]){
[_delButton setHidden:NO];
}else{
[_delButton setHidden:YES];
}
}
- (void)configSubviews {
[self.contentView addSubview:self.avatarImage];
[self.contentView addSubview:self.nameLabel];
[self.contentView addSubview:self.delButton];
UILongPressGestureRecognizer *longPress = [[UILongPressGestureRecognizer alloc]initWithTarget:self action:@selector(longPress:)];
longPress.minimumPressDuration = 1;
[self.contentView addGestureRecognizer:longPress];
}
#pragma mark - Layout
- (void)xw_layoutSubviews {
[self.avatarImage mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.mas_equalTo(self.contentView).offset(margin);
make.centerX.mas_equalTo(self.contentView);
make.size.mas_equalTo(CGSizeMake(45, 45));
}];
[self.delButton mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.mas_equalTo(self.contentView).offset(3);;
make.right.mas_equalTo(self.avatarImage.mas_left).offset(12.5);
make.size.mas_equalTo(CGSizeMake(20, 20));
}];
[self.nameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
make.centerX.mas_equalTo(self.contentView);
make.bottom.mas_equalTo(self.contentView).offset(-margin);
make.left.and.right.mas_lessThanOrEqualTo(self.contentView);
}];
}
#pragma mark - Getter
- (UIButton *)delButton{
if (!_delButton) {
_delButton = [UIButton buttonWithType:UIButtonTypeCustom];
UIImage *image = [self getImageWithImageName:@"privacy_edit_minus" bundleName:@"CNLiveSettingModule" targetClass:[self class]];
[_delButton setBackgroundImage:image forState:UIControlStateNormal];
[_delButton addTarget:self action:@selector(delButtonDidClicked:) forControlEvents:UIControlEventTouchUpInside];
[_delButton setHidden:YES];
}
return _delButton;
}
- (UIImageView *)avatarImage{
if (!_avatarImage) {
_avatarImage = [[UIImageView alloc]init];
_avatarImage.userInteractionEnabled = YES;
}
return _avatarImage;
}
- (UILabel *)nameLabel {
if (!_nameLabel) {
_nameLabel = [[UILabel alloc] init];
[_nameLabel setFont:UIFontMake(14.0)];
[_nameLabel setTextAlignment:NSTextAlignmentCenter];
_nameLabel.textColor = [UIColor blackColor];
}
return _nameLabel;
}
#pragma mark - Action Methods
- (void)delButtonDidClicked:(UIButton *)btn{
if (self.delegate && [self.delegate respondsToSelector:@selector(clickedDel:)]) {
[self.delegate clickedDel:self];
}
}
// 长按手势事件
- (void)longPress:(UILongPressGestureRecognizer *)sender{
if(_model.type == CNLiveNotSeeModelTypeAdd||_model.type == CNLiveNotSeeModelTypeMinus){
return;
}
if (sender.state == UIGestureRecognizerStateBegan) {
if (self.delegate && [self.delegate respondsToSelector:@selector(longPressCell:)]) {
[self.delegate longPressCell:self];
}
}
}
@end