NoDataView.m
2.91 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
//
// NoDataView.m
// CNLiveScioLive
//
// Created by CNLive-zxw on 2018/9/21.
// Copyright © 2018年 CNLive. All rights reserved.
//
#import "NoDataView.h"
@interface NoDataView()
@property (nonatomic, strong) UIImageView *noImage;
@property (nonatomic, strong) UILabel *noTitle;
@property (nonatomic, strong) UIButton *clickedBtn;
@end
@implementation NoDataView
- (instancetype)initWithFrame:(CGRect)frame{
self = [super initWithFrame:frame];
if(self){
[self setUpUI];
}
return self;
}
- (void)setImage:(NSString *)image{
_noImage.hidden = NO;
_image = image;
_noImage.image = [UIImage imageNamed:image];
}
- (void)setTitle:(NSString *)title{
_noTitle.hidden = NO;
_title = title;
_noTitle.text = title;
}
- (void)setBtnTitle:(NSString *)btnTitle{
_clickedBtn.hidden = NO;
_btnTitle = btnTitle;
[_clickedBtn setTitle:btnTitle forState:UIControlStateNormal];
}
- (void)setUpUI{
self.noImage = [[UIImageView alloc] init];
_noImage.contentMode = UIViewContentModeCenter;
_noImage.backgroundColor = [UIColor blueColor];
_noImage.layer.masksToBounds = YES;
_noImage.userInteractionEnabled = YES;
_noImage.hidden = YES;
[self addSubview:_noImage];
self.noTitle = [[UILabel alloc] init];
_noTitle.numberOfLines = 1;
_noTitle.textColor = HEXCOLOR(0x333333);
_noTitle.textAlignment = NSTextAlignmentCenter;
_noTitle.font = [UIFont systemFontOfSize:18];
_noTitle.hidden = YES;
[self addSubview:_noTitle];
self.clickedBtn = [UIButton buttonWithType:UIButtonTypeCustom];
[_clickedBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
_clickedBtn.titleLabel.font = [UIFont systemFontOfSize:14];
_clickedBtn.layer.borderColor = [UIColor whiteColor].CGColor;
_clickedBtn.layer.borderWidth = 1;
_clickedBtn.layer.cornerRadius = 5;
_clickedBtn.layer.masksToBounds = YES;
_clickedBtn.backgroundColor = Color_Blue;
_clickedBtn.hidden = YES;
[_clickedBtn addTarget:self action:@selector(clickedLoadingBtn) forControlEvents:UIControlEventTouchUpInside];
[self addSubview:self.clickedBtn];
}
- (void)layoutSubviews{
[_noTitle mas_makeConstraints:^(MASConstraintMaker *make) {
make.centerX.equalTo(self.mas_centerX);
make.centerY.equalTo(self.mas_centerY);
}];
[_noImage mas_makeConstraints:^(MASConstraintMaker *make) {
make.bottom.equalTo(self->_noTitle.mas_top).with.offset(-20);
make.centerX.equalTo(self.mas_centerX);
make.width.offset(200);
make.height.offset(200);
}];
[_clickedBtn mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.equalTo(self->_noTitle.mas_bottom).with.offset(20);
make.centerX.equalTo(self.mas_centerX);
make.width.offset(100);
make.height.offset(40);
}];
}
- (void)clickedLoadingBtn{
self.block?self.block():@"";
}
@end