123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242 |
- //
- // ZYLEmptyDataView.m
- // mask
- //
- // Created by 翟玉磊 on 2018/12/9.
- // Copyright © 2018 翟玉磊. All rights reserved.
- //
- #import "ZYLEmptyDataView.h"
- const CGFloat DefaultOffsetTop = 250;
- @interface ZYLEmptyDataView ()
- /// imageView <图片>
- @property (nonatomic , readwrite , weak) UIImageView *imageView;
- /// tipsLabel <信息提示>
- @property (nonatomic , readwrite , weak) UILabel *tipsLabel;
- /// 重新加载
- @property (nonatomic , readwrite , weak) UIButton *reloadButton;
- /** 重新加载block */
- @property (nonatomic , readwrite , copy) void(^reloadBlock)(void);
- @end
- @implementation ZYLEmptyDataView
- #pragma mark - Public Method
- - (void)configEmptyViewWithType:(ZYLEmptyDataViewType)type emptyInfo:(NSString *)emptyInfo errorInfo:(NSString *)errorInfo offsetTop:(CGFloat)offsetTop hasData:(BOOL)hasData hasError:(BOOL)hasError reloadBlock:(void(^)(void))reloadBlock{
-
- if (hasData) { /// 有数据,则不需要显示占位图
- self.hidden = YES;
- [self removeFromSuperview];
- return;
- }
-
- [self.imageView mas_updateConstraints:^(MASConstraintMaker *make) {
- make.centerY.equalTo(self.mas_top).with.offset(offsetTop);
- }];
-
- self.reloadButton.hidden = ObjectIsNil(reloadBlock);
- self.reloadBlock = reloadBlock;
- /// 没有数据的情况 1. 确实没有数据 2. 请求出错导致无数据
- self.hidden = NO;
-
- UIImage *image = nil;
- if (hasError) { /// 请求出错 1. 网络问题 2. 服务器问题
- if (![ZYLAPPContext sharedInstance].isReachable) { /// 无网络
- errorInfo = StringIsNotEmpty(errorInfo)?errorInfo:@"呀!网络正在开小差~";
- image = [UIImage imageNamed:@"icon_nodata_default"];
- }else{ /// 服务器出错
- errorInfo = StringIsNotEmpty(errorInfo)?errorInfo:@"呜呜!服务器崩溃了~";
- image = [UIImage imageNamed:@"icon_nodata_default"];
- }
-
- /// 赋值
- self.imageView.image = image;
- self.tipsLabel.text = errorInfo;
- return;
- }
-
-
- /// 无数据
- switch (type) {
- case ZYLEmptyDataViewTypeDefault: /// 默认情况
- {
- emptyInfo = StringIsNotEmpty(emptyInfo)?emptyInfo:kLocalizedString(@"暂无数据");
- image = ImageNamed(@"icon_nodata_default");
- }
- break;
- case ZYLEmptyDataViewTypeNoData: /// 电脑图片空界面
- {
- emptyInfo = StringIsNotEmpty(emptyInfo)?emptyInfo:kLocalizedString(@"暂无数据");
- image = ImageNamed(@"icon_nodata_home");
- }
- break;
- case ZYLEmptyDataViewTypeSearchPersonal:
- {
- emptyInfo = StringIsNotEmpty(emptyInfo)?emptyInfo:kLocalizedString(@"没有找到符合条件的人");
- image = [UIImage imageNamed:@"icon_nodata_default"];
- }
- break;
- case ZYLEmptyDataViewTypeNoLogin:
- {
- emptyInfo = StringIsNotEmpty(emptyInfo)?emptyInfo:kLocalizedString(@"登陆后才能查看信息");
- // image = [UIImage imageNamed:@"icon_noData_default"];
- [self.reloadButton setTitle:kLocalizedString(@"去登陆") forState:UIControlStateNormal];
- }
- break;
- case ZYLEmptyDataViewTypeAnchorApply:
- {
- emptyInfo = StringIsNotEmpty(emptyInfo)?emptyInfo:kLocalizedString(@"为了你的账户安全\n 请通过实名认证绑定账户");
- image = [UIImage imageNamed:@"icon_nodata_apply"];
- }
- break;
- case ZYLEmptyDataViewTypeNoAttention:
- {
- emptyInfo = StringIsNotEmpty(emptyInfo)?emptyInfo:kLocalizedString(@"暂时没有关注");
- image = [UIImage imageNamed:@"icon_nodata_attention"];
- }
- break;
- case ZYLEmptyDataViewTypeNoCoin:
- {
- emptyInfo = StringIsNotEmpty(emptyInfo)?emptyInfo:[NSString stringWithFormat:@"%@%@", kLocalizedString(@"暂时没有"), App_CoinName(Wallet_Type_Star_Diamond)];
- image = [UIImage imageNamed:@"icon_nodata_coin"];
- }
- break;
- case ZYLEmptyDataViewTypeNoRecharge:
- {
- emptyInfo = StringIsNotEmpty(emptyInfo)?emptyInfo:kLocalizedString(@"暂时没有充值");
- image = [UIImage imageNamed:@"icon_nodata_recharge"];
- }
- break;
- case ZYLEmptyDataViewTypeNoRecord:
- {
- emptyInfo = StringIsNotEmpty(emptyInfo)?emptyInfo:kLocalizedString(@"暂时没有记录");
- image = [UIImage imageNamed:@"icon_nodata_record"];
- }
- break;
- case ZYLEmptyDataViewTypeNoSubscribe:
- {
- emptyInfo = StringIsNotEmpty(emptyInfo)?emptyInfo:kLocalizedString(@"暂时没有订阅");
- image = [UIImage imageNamed:@"icon_nodata_subscribe"];
- }
- break;
- case ZYLEmptyDataViewTypeNoVisitor:
- {
- emptyInfo = StringIsNotEmpty(emptyInfo)?emptyInfo:kLocalizedString(@"暂时没有访客");
- image = [UIImage imageNamed:@"icon_nodata_visitor"];
- }
- break;
- case ZYLEmptyDataViewTypeNoLiveCategory:
- {
- emptyInfo = StringIsNotEmpty(emptyInfo)?emptyInfo:kLocalizedString(@"请查看网络状态");
- image = [UIImage imageNamed:@"icon_nodata_default"];
- [self.reloadButton setTitle:kLocalizedString(@"重新连接") forState:UIControlStateNormal];
- }
- break;
- case ZYLEmptyDataViewTypeNoSkillCertification:
- {
- emptyInfo = StringIsNotEmpty(emptyInfo)?emptyInfo:kLocalizedString(@"您还没有认证技能,请前去认证");
- image = [UIImage imageNamed:@"icon_nodata_default"];
- [self.reloadButton setTitle:kLocalizedString(@"立即认证") forState:UIControlStateNormal];
- }
- break;
- default:
- {
- emptyInfo = StringIsNotEmpty(emptyInfo)?emptyInfo:@"~ 敬请期待 ~";
- image = [UIImage imageNamed:@"icon_nodata_default"];
- }
- break;
- }
-
- /// 赋值
- self.imageView.image = image;
- self.tipsLabel.text = emptyInfo;
- }
- #pragma mark - Private Method
- - (instancetype)initWithFrame:(CGRect)frame{
- if (self = [super initWithFrame:frame]) {
- // 初始化
- [self _setup];
-
- // 创建自控制器
- [self _setupSubViews];
-
- // 布局子控件
- [self _makeSubViewsConstraints];
- }
- return self;
- }
- #pragma mark - 事件处理Or辅助方法
- - (void)_reloadBtnDidClicked:(UIButton *)sender{
- dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.1 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
- !self.reloadBlock?:self.reloadBlock();
- });
- }
- #pragma mark - Private Method
- - (void)_setup{
- /// 设置界面背景颜色
- self.backgroundColor = Color_Clear;
- }
- #pragma mark - 创建自控制器
- - (void)_setupSubViews{
-
- /// imageView
- UIImageView *imageView = [[UIImageView alloc] init];
- self.imageView = imageView;
- [self addSubview:imageView];
-
- /// tipsLabel
- UILabel *tipsLabel = [[UILabel alloc] initWithFrame:CGRectZero];
- tipsLabel.text = nil;
- tipsLabel.numberOfLines = 0;
- tipsLabel.font = Font_B(14);
- tipsLabel.textColor = Color_TextGray;
- tipsLabel.textAlignment = NSTextAlignmentCenter;
- self.tipsLabel = tipsLabel;
- [self addSubview:tipsLabel];
-
- /// reloadButton
- UIButton * reloadButton = [[UIButton alloc] initWithFrame:CGRectZero];
- reloadButton.titleLabel.font =[UIFont systemFontOfSize:18.f];
- [reloadButton setTitleColor:Color_White forState:UIControlStateNormal];
- [reloadButton setTitle:kLocalizedString(@"重新连接") forState:UIControlStateNormal];
- reloadButton.adjustsImageWhenHighlighted = YES;
- [reloadButton setBackgroundImage:[UIImage commonRedGradientColorImageWithImgSize:CGSizeMake(160.0f, 40.0f)] forState:UIControlStateNormal];
- [reloadButton addTarget:self action:@selector(_reloadBtnDidClicked:) forControlEvents:UIControlEventTouchUpInside];
- self.reloadButton = reloadButton;
- [self addSubview:reloadButton];
- }
- #pragma mark - 布局子控件
- - (void)_makeSubViewsConstraints{
- [self.imageView mas_makeConstraints:^(MASConstraintMaker *make) {
- make.centerX.equalTo(self);
- make.width.height.equalTo(@(VWIDTH * 120.0f));
- make.centerY.equalTo(self.mas_top).with.offset(0);
- }];
-
- [self.tipsLabel mas_makeConstraints:^(MASConstraintMaker *make) {
- make.left.right.centerX.equalTo(self);
- make.top.equalTo(self.imageView.mas_bottom);
- make.height.mas_equalTo(50);
- }];
-
- [self.reloadButton mas_makeConstraints:^(MASConstraintMaker *make) {
- make.centerX.equalTo(self);
- make.top.equalTo(self.tipsLabel.mas_bottom).offset(20.0f);
- make.size.mas_equalTo(CGSizeMake(144, 40));
- }];
-
- [self.reloadButton addViewBorder:Color_Clear redian:4];
- }
- @end
|