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
//
// GMEmptyView.m
// Gengmei
//
// Created by Terminator on 15/10/16.
// Copyright © 2015年 Wanmeichuangyi. All rights reserved.
//
#import "GMEmptyView.h"
#import <Masonry/Masonry.h>
#import "GMButton.h"
#import "GMFont.h"
#import "UIView+Layout.h"
#import <UIColor+GMTheme.h>
#import <Constant.h>
#import <GMPhobos/Phobos.h>
#import <GMPhobos/UIResponder+PhobosPV.h>
@interface GMEmptyView()
@property (nonatomic, strong) UIButton *serviceBtn;;
@end
@implementation GMEmptyView
- (instancetype)initWithFrame:(CGRect)frame {
self = [super initWithFrame:frame];
if (self) {
_iconTop = 155;
[self setup];
}
return self;
}
- (void)awakeFromNib {
[super awakeFromNib];
[self setup];
}
- (void)setup {
self.backgroundColor = UIColor.whiteColor;
}
- (void)setType:(GMEmptyViewType)type{
_type = type;
switch (self.type) {
case GMEmptyViewTypeEmpty:{
self.tipLabel.textColor = UIColor.bodyText;
self.tipButton.hidden = YES;
self.checkNetworkButton.hidden = YES;
self.serviceBtn.hidden = YES;
self.tipIcon.image = [UIImage imageNamed:@"empty"];
self.tipLabel.text = @"此处太寂寥,社区等你撩";
break;
}
case GMEmptyViewTypeException:{
self.tipLabel.textColor = UIColor.bodyText;
self.tipButton.hidden = NO;
self.checkNetworkButton.hidden = YES;
self.serviceBtn.hidden = YES;
self.tipIcon.image = [UIImage imageNamed:@"network_failed"];
self.tipLabel.text = @"原谅我一看到美人就不淡定";
break;
}
case GMEmptyViewTypeService:{
self.tipButton.hidden = YES;
self.checkNetworkButton.hidden = YES;
self.serviceBtn.hidden = NO;
self.tipIcon.image = [UIImage imageNamed:@"search_result_empty"];
[self.serviceBtn setBackgroundImage:[UIImage imageNamed:@"empty_service"] forState:UIControlStateNormal];
[self.serviceBtn setBackgroundImage:[UIImage imageNamed:@"empty_service"] forState:UIControlStateHighlighted];
self.tipLabel.textColor = RGBCOLOR_HEX(0x666666);
self.tipLabel.text = @"找不到合适的机构?撩一下更美咨询师吧~";
break;
}
default:
break;
}
[self updateViewConstraints];
}
- (void)updateViewConstraints {
[self.tipIcon mas_remakeConstraints:^(MASConstraintMaker *make) {
make.top.mas_equalTo(self.iconTop);
make.centerX.mas_equalTo(0);
}];
[self.tipLabel mas_remakeConstraints:^(MASConstraintMaker *make) {
make.bottom.equalTo(self.tipIcon.mas_bottom).offset(-15);
make.centerX.mas_equalTo(0);
}];
[self.tipButton mas_remakeConstraints:^(MASConstraintMaker *make) {
make.top.equalTo(self.tipIcon.mas_bottom).offset(10);
make.centerX.mas_equalTo(0);
make.width.mas_equalTo(150);
make.height.mas_equalTo(33);
}];
[self.checkNetworkButton mas_remakeConstraints:^(MASConstraintMaker *make) {
make.top.equalTo(self.tipIcon.mas_bottom).offset(10);
make.centerX.mas_equalTo(0);
make.width.mas_equalTo(150);
make.height.mas_equalTo(33);
}];
[self.serviceBtn mas_remakeConstraints:^(MASConstraintMaker *make) {
make.top.equalTo(self.tipIcon.mas_bottom).offset(10);
make.centerX.mas_equalTo(0);
make.width.mas_equalTo(125);
make.height.mas_equalTo(35);
}];
}
- (void)clickService {
if ([self.delegate respondsToSelector:@selector(emptyViewDidClickService)]) {
[self.delegate emptyViewDidClickService];
}
}
- (void)reloadBtnTap {
if ([self.delegate respondsToSelector:@selector(emptyViewDidClickReload)]) {
[self.delegate emptyViewDidClickReload];
}
}
- (void)checkNetwork {
if ([self.delegate respondsToSelector:@selector(emptyViewDidClickSettingNetWork)]) {
[self.delegate emptyViewDidClickSettingNetWork];
}
NSURL *appSettings = [NSURL URLWithString:UIApplicationOpenSettingsURLString];
[[UIApplication sharedApplication] openURL:appSettings];
}
#pragma mark - UILabel
- (UIImageView *)tipIcon {
if (!_tipIcon) {
_tipIcon = [UIImageView new];
[self addSubview:_tipIcon];
}
return _tipIcon;
}
- (UILabel *)tipLabel {
if (!_tipLabel) {
_tipLabel = [UILabel new];
_tipLabel.numberOfLines = 2;
_tipLabel.preferredMaxLayoutWidth = 300;
_tipLabel.textColor = UIColor.bodyText;
_tipLabel.font = [UIFont gmFont:15];
_tipLabel.textAlignment = NSTextAlignmentCenter;
[self.tipIcon addSubview:_tipLabel];
}
return _tipLabel;
}
-(GMButton *)tipButton {
if (!_tipButton) {
_tipButton = [GMButton buttonWithCustomType:GMButtonTypeRedSemicircleGradient];
_tipButton.hidden = YES;
[_tipButton setTitle:@"重新加载" forState:UIControlStateNormal];
_tipButton.titleLabel.font = [UIFont gmFont:16];
[_tipButton setTitleColor:UIColor.bodyText forState:UIControlStateNormal];
[_tipButton addTarget:self action:@selector(reloadBtnTap) forControlEvents:UIControlEventTouchUpInside];
[self addSubview:_tipButton];
}
return _tipButton;
}
- (GMButton *)checkNetworkButton {
if (!_checkNetworkButton) {
//给一个默认的rect,让系统调用DrawRect方法
_checkNetworkButton = [GMButton buttonWithCustomType:GMButtonTypeGraySemicircleBorder];
[_checkNetworkButton setTitle:@"检查网络设置" forState:UIControlStateNormal];
_checkNetworkButton.titleLabel.font = [UIFont gmFont:16];
[_checkNetworkButton setTitleColor:[UIColor colorWithHex:0xFF6080] forState:UIControlStateNormal];
_checkNetworkButton.layer.borderColor = [UIColor colorWithHex:0xFF5963].CGColor;
[_checkNetworkButton setBackgroundColor:[UIColor colorWithHex:0xFFFFFF] forState:UIControlStateNormal];
[_checkNetworkButton setBackgroundColor:[UIColor colorWithHex:0xFFFFFF] forState:UIControlStateHighlighted];
_checkNetworkButton.hidden = YES;
[_checkNetworkButton addTarget:self action:@selector(checkNetwork) forControlEvents:UIControlEventTouchUpInside];
[self addSubview:_checkNetworkButton];
}
return _checkNetworkButton;
}
- (UIButton *)serviceBtn {
if (!_serviceBtn) {
_serviceBtn = [UIButton buttonWithType:UIButtonTypeCustom];
[_serviceBtn addTarget:self action:@selector(clickService) forControlEvents:UIControlEventTouchUpInside];
[self addSubview:_serviceBtn];
}
return _serviceBtn;
}
@end