#2.0.0 移除UIWebView
_emptyView = [XKEmptyPlaceView configScrollView:self.tableView config:nil];
[_emptyView showWithImgName:@"xxx" title:@"xxx" des:nil tapClick:^{ }];
可以使用属性存储XKEmptyPlaceView对象,配置后调用占位图的方法显示隐藏。为了方便使用,给UIScrollView加了一个分类,可以不用申明属性,快速使用占位图
// 初始化方法
[self.tableView configDefaultEmptyView];
[self.tableView.emptyPlaceView showWithImgName:@"xxx" title:@"xxxx" des:nil tapClick:^{ }];
[HTTPClient postXXXX:^(id responseObject) {
self.datas = xxx;
if (self.datas.count) {
[self.emptyTipView hide];
} else {
[self.emptyTipView showWithImgName:kEmptyPlaceImgName title:nil des:@"暂无数据" tapClick:nil];
}
} failure:^(XKHttpErrror *error) {
if (self.datas.count == 0) {
__weak typeof(self) weakSelf = self;
self.emptyTipView.config.viewAllowTap = YES;
[self.emptyTipView showWithImgName:kNetErrorPlaceImgName title:@"网络错误" des:@"点击屏幕重试" tapClick:^{
[weakSelf request];
}];
}
}];
__weak typeof(self) weakSelf = self;
_emptyView = [XKEmptyPlaceView configScrollView:self.tableView config:nil];
[_emptyView showWithImgName:@"暂无内容" title:@"暂无数据" des:nil tapClick:^{
//
}];
__weak typeof(self) weakSelf = self;
_emptyView = [XKEmptyPlaceView configScrollView:self.tableView config:nil];
[_emptyView showWithImgName:@"加载失败" title:@"无法获取网络" des:@"点击屏幕重试" tapClick:^{
[weakSelf.emptyView hide];
}];
__weak typeof(self) weakSelf = self;
_emptyView = [XKEmptyPlaceView configScrollView:self.tableView config:nil];
_emptyView.config.viewAllowTap = NO;
[_emptyView showWithImgName:@"加载失败" title:@"无法获取网络" des:@"请检查网络" btnText:@"重试" btnImg:nil tapClick:^{
[weakSelf.emptyView hide];
}];
- (void)viewDidLoad {
[super viewDidLoad];
__weak typeof(self) weakSelf = self;
XMEmptyViewConfig *config = [XMEmptyViewConfig new];
config.titleFont = [UIFont systemFontOfSize:18];
config.verticalOffset = -50;
config.btnBackImg = [UIColor orangeColor];
config.btnColor = [UIColor whiteColor];
config.btnFont = [UIFont systemFontOfSize:18];
config.btnMargin = 50;
config.spaceDesBtmHeight = 20;
config.spaceTitleBtmHeight = 30;
_emptyView = [XKEmptyPlaceView configScrollView:self.tableView config:config];
[self showNetError];
}
- (void)showNetError {
__weak typeof(self) weakSelf = self;
// 展示前可继续动态配置config
self.emptyView.config.viewAllowTap = NO;
_emptyView.config.titleColor = [UIColor blackColor];
[_emptyView showWithImgName:@"404出错页面" title:@"不开心\n无法获取网络" des:@"检查一下网络" btnText:@"重试" btnImg:nil tapClick:^{
[weakSelf showEmpty];
}];
}
- (void)showEmpty {
__weak typeof(self) weakSelf = self;
_emptyView.config.viewAllowTap = YES;
_emptyView.config.titleColor = [UIColor orangeColor];
[_emptyView showWithImgName:@"暂无内容" title:@"暂无数据" des:@"戳屏幕再刷新" tapClick:^{
[weakSelf showNetError];
}];
}
3. emptyView自带有config属性,初始化未为传入会自动生成一个默认的config,针对自己的app设计,可以将基础的配置项在默认配置里设置完,外界只配置特殊的。 在展示前可获取congfig进行属性配置,即可继续动态配置占位图的显示效果。 config的界面配置属性如果设置过多,显示其他界面不需要时,可重置,设置可调用resetConfig
/**不带按钮的占位图*/
- (void)showWithImgName:(NSString *)imgName title:(NSString *)title des:(NSString *)des tapClick:(void(^)(void))tap;
/**下方带按钮的 btnImg 可是image or 图片名称*/
- (void)showWithImgName:(NSString *)imgName title:(NSString *)title des:(NSString *)des btnText:(NSString *)btnText btnImg:(id)btnImg tapClick:(void(^)(void))tap;
XKEmptyPlaceView is available through CocoaPods. To install it, simply add the following line to your Podfile:
pod 'XKEmptyPlaceView'
Jamesholy, 447523382@qq.com