DZNEmptyDataSet空白Tableview背景的使用
程序员文章站
2022-06-01 10:25:40
...
DZNEmptyDataSet 简单的来说就是用来管理我们tableview数据源为空的时候需要展示什么的一个很强大的控件,废话不多说先上效果图:
首先你要设置一下代理:
_tableView.emptyDataSetSource = self;
_tableView.emptyDataSetDelegate = self;
记得要服从协议 <DZNEmptyDataSetSource, DZNEmptyDataSetDelegate>
下面是代理方法:
#define kFont_MainRegularWithSize(fontSize) [UIFont fontWithName:kFont_PingFangSCRegular size:fontSize]
#pragma mark ---------- DZNEmptyDataSetSource & DZNEmptyDataSetDelegate ----------
// 这里是你文字需要展示什么就写什么就可以了
- (NSAttributedString *)titleForEmptyDataSet:(UIScrollView *)scrollView {
NSString *title = @"暂无订单";
NSDictionary *attributes = @{NSFontAttributeName:kFont_MainRegularWithSize(14),NSForegroundColorAttributeName:
kColor_HexString(@"#666666")};
return [[NSAttributedString alloc] initWithString:title attributes:attributes];
}
- (CGFloat)verticalOffsetForEmptyDataSet:(UIScrollView *)scrollView {
return -90;
}
// 这是图片 文字 和 button的间距
- (CGFloat)spaceHeightForEmptyDataSet:(UIScrollView *)scrollView {
return 40;
}
// 这里是你需要显示的大图是就放一个本地的路径就可以了
- (UIImage *)imageForEmptyDataSet:(UIScrollView *)scrollView {
return [UIImage imageNamed:@"myorder_kongdingdan"];
}
- (NSAttributedString *)buttonTitleForEmptyDataSet:(UIScrollView *)scrollView forState:(UIControlState)state {
NSString *buttonTitle = @"返回首页";
NSDictionary *attributes = @{NSFontAttributeName:kFont_MainRegularWithSize(18),NSForegroundColorAttributeName:kColor_HexString(@"#F5F5F9")};
return [[NSAttributedString alloc] initWithString:buttonTitle attributes:attributes];
}
- (nullable UIImage *)buttonBackgroundImageForEmptyDataSet:(UIScrollView *)scrollView forState:(UIControlState)state {
NSString *imageName = [[NSString stringWithFormat:@"mineorder_backgroundbutton"] lowercaseString];
UIEdgeInsets capInsets = UIEdgeInsetsMake(0, 0, 0, 0);
UIEdgeInsets rectInsets = UIEdgeInsetsZero;
UIImage *image = [UIImage imageNamed:imageName inBundle:[NSBundle bundleForClass:[self class]] compatibleWithTraitCollection:nil];
return [[image resizableImageWithCapInsets:capInsets resizingMode:UIImageResizingModeStretch] imageWithAlignmentRectInsets:rectInsets];
}
- (void)emptyDataSet:(UIScrollView *)scrollView didTapButton:(UIButton *)button {
}