- 添加依赖
pod 'DZNEmptyDataSet'
- 引入头文件
#import "UIScrollView+EmptyDataSet.h"
- 实现接口
<DZNEmptyDataSetSource, DZNEmptyDataSetDelegate>
- 设置代理
//空布局代理
_tableView.emptyDataSetSource = self;
_tableView.emptyDataSetDelegate = self;
- 实现方法
#pragma mark DZNEmptyDataSet (当没有数据的时候设置背景颜色)
- (UIColor *)backgroundColorForEmptyDataSet:(UIScrollView *)scrollView
{
return [UIColor colorWithHexString:@"#F2F3F7"];
}
#pragma mark DZNEmptyDataSet 返回展示空布局的图片
- (UIImage *)imageForEmptyDataSet:(UIScrollView *)scrollView
{
return [UIImage imageNamed:@"empty_icon"];
}
#pragma mark DZNEmptyDataSet (返回标题)
- (NSAttributedString *)titleForEmptyDataSet:(UIScrollView *)scrollView
{
NSString *text = @"哦哦~暂无数据";
UIFont *font = [UIFont systemFontOfSize:16];
UIColor *color = [UIColor colorWithHexString:@"#999999"];
NSMutableDictionary *attribult = [NSMutableDictionary new];
[attribult setObject:font forKey:NSFontAttributeName];
[attribult setObject:color forKey:NSForegroundColorAttributeName];
return [[NSAttributedString alloc] initWithString:text attributes:attribult];
}