DZNEmptyDataSet使用(UItabelView 数据为空时 显示图)
来源:互联网 发布:xampp是什么软件 编辑:程序博客网 时间:2024/06/05 14:54
感谢万能的github下载地址:DZNEmptyDataSet https://github.com/dzenbot/DZNEmptyDataSet上效果首先在你的ViewController里面导入#import "UIScrollView+EmptyDataSet.h"遵守 <DZNEmptyDataSetSource, DZNEmptyDataSetDelegate> 协议`@interface MainViewController : UITableViewController <DZNEmptyDataSetSource, DZNEmptyDataSetDelegate>(void)viewDidLoad{[super viewDidLoad];self.tableView.emptyDataSetSource = self;self.tableView.emptyDataSetDelegate = self; // A little trick for removing the cell separators self.tableView.tableFooterView = [UIView new];}
返回单张图片
Data Source 实现方法- (UIImage *)imageForEmptyDataSet:(UIScrollView *)scrollView{ return [UIImage imageNamed:@"empty_placeholder"];}
返回标题文字
- (NSAttributedString *)titleForEmptyDataSet:(UIScrollView *)scrollView{ NSString *text = @"Please Allow Photo Access"; NSDictionary *attributes = @{NSFontAttributeName: [UIFont boldSystemFontOfSize:18.0f], NSForegroundColorAttributeName: [UIColor darkGrayColor]}; return [[NSAttributedString alloc] initWithString:text attributes:attributes];}
返回文字详情
- (NSAttributedString *)descriptionForEmptyDataSet:(UIScrollView *)scrollView{ NSString *text = @"This allows you to share photos from your library and save photos to your camera roll."; NSMutableParagraphStyle *paragraph = [NSMutableParagraphStyle new]; paragraph.lineBreakMode = NSLineBreakByWordWrapping; paragraph.alignment = NSTextAlignmentCenter; NSDictionary *attributes = @{NSFontAttributeName: [UIFont systemFontOfSize:14.0f], NSForegroundColorAttributeName: [UIColor lightGrayColor], NSParagraphStyleAttributeName: paragraph}; return [[NSAttributedString alloc] initWithString:text attributes:attributes]; }
返回可以点击的按钮 上面带文字
- (NSAttributedString *)buttonTitleForEmptyDataSet:(UIScrollView *)scrollView forState:(UIControlState)state{ NSDictionary *attributes = @{NSFontAttributeName: [UIFont boldSystemFontOfSize:17.0f]}; return [[NSAttributedString alloc] initWithString:@"Continue" attributes:attributes];}
返回可以点击的按钮 上面带图片
- (UIImage *)buttonImageForEmptyDataSet:(UIScrollView *)scrollView forState:(UIControlState)state{ return [UIImage imageNamed:@"button_image"];}
返回空白区域的颜色 自定义
- (UIColor *)backgroundColorForEmptyDataSet:(UIScrollView *)scrollView{ return [UIColor whiteColor];}
返回一个自定义的View
(UIView )customViewForEmptyDataSet:(UIScrollView )scrollView{ UIActivityIndicatorView *activityView = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleGray]; [activityView startAnimating]; return activityView;}
此外,您还可以调整垂直对齐的内容视图(即:有用tableHeaderView时可见):
- (CGFloat)verticalOffsetForEmptyDataSet:(UIScrollView *)scrollView{ return -self.tableView.tableHeaderView.frame.size.height/2.0f;
返回间距离
(CGFloat)verticalOffsetForEmptyDataSet:(UIScrollView *)scrollView{ return -self.tableView.tableHeaderView.frame.size.height/2.0f;}
委托实现
要求知道空的状态应该渲染和显示 (Default is YES) :
- (BOOL)emptyDataSetShouldDisplay:(UIScrollView *)scrollView{ return YES;}
是否允许点击 (默认是 YES) :
- (BOOL)emptyDataSetShouldAllowTouch:(UIScrollView *)scrollView{ return YES;}
是否允许滚动 (默认是 NO) :
- (BOOL)emptyDataSetShouldAllowScroll:(UIScrollView *)scrollView{ return YES;}
空白区域点击响应:
- (void)emptyDataSetDidTapView:(UIScrollView *)scrollView{ // Do something}
点击button 响应
- (void)emptyDataSetDidTapButton:(UIScrollView *)scrollView{ // Do something}
刷新当前表格
[self.tableView reloadData];
或者
[self.collectionView reloadData];
_会飞的鱼(简书作者)
原文链接:http://www.jianshu.com/p/d30a143a17e1
0 0
- DZNEmptyDataSet使用(UItabelView 数据为空时 显示图)
- DZNEmptyDataSet UItabelView空数据 背景图的实现
- DZNEmptyDataSet空白数据集显示框架简单使用
- iOS【TableView-CollectionView 空状态加载视图DZNEmptyDataSet—空白数据集显示框架】
- “空”的艺术-当数据为空时显示什么
- “空”的艺术-当数据为空时显示什么
- “空”的艺术-当数据为空时显示什么
- “空”的艺术-当数据为空时显示什么
- iOS空页面 DZNEmptyDataSet
- listview设置数据为空时显示数据
- DZNEmptyDataSet——空白数据集显示框架
- gridview数据绑定为空时显示提示
- ArcMap中添加gdb数据时显示为空问题
- datalist 绑定数据为空时,显示提示信息
- EmptyRecyclerView 数据为空时显示指定view
- 数据为空的时候显示表头
- 使用ibaits 查询数据时,如果结果为空,将报错。
- Opencv使用imread函数时,读到的数据为空
- threadLocal的比喻很到位
- ASP.NET Session 详解
- AlarmManager
- jQuery的deferred对象详解
- Fortran 编译出现error #7938: Character length argument mismatch
- DZNEmptyDataSet使用(UItabelView 数据为空时 显示图)
- 【MyBatis框架点滴】——MyBatis一级缓存
- UVA 11729 Commando War
- POJ 3417 LCA+DFS
- Ubuntu12.04 上网静态IP配置方法
- LightOJ 1027 A Dangerous Maze
- 子集继承父级的妙用
- spark机器学习笔记:(一)Spark Python初探
- tar 归档中找不到