- 添加依賴
pod 'DZNEmptyDataSet'
- 引入頭文件
#import "UIScrollView+EmptyDataSet.h"
- 實(shí)現(xiàn)接口
<DZNEmptyDataSetSource, DZNEmptyDataSetDelegate>
- 設(shè)置代理
//空布局代理
_tableView.emptyDataSetSource = self;
_tableView.emptyDataSetDelegate = self;
- 實(shí)現(xiàn)方法
#pragma mark DZNEmptyDataSet (當(dāng)沒有數(shù)據(jù)的時(shí)候設(shè)置背景顏色)
- (UIColor *)backgroundColorForEmptyDataSet:(UIScrollView *)scrollView
{
return [UIColor colorWithHexString:@"#F2F3F7"];
}
#pragma mark DZNEmptyDataSet 返回展示空布局的圖片
- (UIImage *)imageForEmptyDataSet:(UIScrollView *)scrollView
{
return [UIImage imageNamed:@"empty_icon"];
}
#pragma mark DZNEmptyDataSet (返回標(biāo)題)
- (NSAttributedString *)titleForEmptyDataSet:(UIScrollView *)scrollView
{
NSString *text = @"哦哦~暫無(wú)數(shù)據(jù)";
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];
}