// // GMEmptyView.m // Gengmei // // Created by Terminator on 15/10/16. // Copyright © 2015年 Wanmeichuangyi. All rights reserved. // #import "GMEmptyView.h" #import #import "GMButton.h" #import "GMFont.h" #import "UIView+Layout.h" #import #import #import #import @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