DZNEmptyDataSet,优秀的空白页或者出错页封装
来源:互联网 发布:手机全包壳 知乎 编辑:程序博客网 时间:2024/06/01 16:25
## 简介
项目主页:https://github.com/dzenbot/DZNEmptyDataSet
提示:主要用于UITableView和UICollectionView,也可以用于UIScrollView,其实主要是前两个会用到空白或者网络出错页
采用给UIScrollView添加代理方法来给页面添加空白页,源码很有学习意义
导入工程
自动,
pod 'DZNEmptyDataSet'
手动
https://github.com/dzenbot/DZNEmptyDataSet 下载解压,Source文件夹下的文件拖入工程
导入头文件:
#import "UIScrollView+EmptyDataSet.h"
初始化
@interface MainViewController : UITableViewController <DZNEmptyDataSetSource, DZNEmptyDataSetDelegate> - (void)viewDidLoad { [super viewDidLoad]; self.tableView.emptyDataSetSource = self; self.tableView.emptyDataSetDelegate = self; //这行代码必须加上,可以去除tableView的多余的线,否则会影响美观 self.tableView.tableFooterView = [UIView new]; }
满足代理方法,可以分别配置,都是可选的
空白页图片
- (UIImage *)imageForEmptyDataSet:(UIScrollView *)scrollView { return [UIImage imageNamed:@"empty_placeholder"]; }
图片的动画效果
- (CAAnimation *)imageAnimationForEmptyDataSet:(UIScrollView *)scrollView { CABasicAnimation *animation = [CABasicAnimation animationWithKeyPath: @"transform"]; animation.fromValue = [NSValue valueWithCATransform3D:CATransform3DIdentity]; animation.toValue = [NSValue valueWithCATransform3D:CATransform3DMakeRotation(M_PI_2, 0.0, 0.0, 1.0)]; animation.duration = 0.25; animation.cumulative = YES; animation.repeatCount = MAXFLOAT; return animation; }
标题文本,详细描述,富文本样式
- (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]; }
如果需求无法满足,你可以自定义
- (UIView *)customViewForEmptyDataSet:(UIScrollView *)scrollView { //加入你自定义的view UIActivityIndicatorView *activityView = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleGray]; [activityView startAnimating]; return activityView; }
其他需求
//是否显示空白页,默认YES - (BOOL)emptyDataSetShouldDisplay:(UIScrollView *)scrollView { return YES; } //是否允许点击,默认YES - (BOOL)emptyDataSetShouldAllowTouch:(UIScrollView *)scrollView { return YES; } //是否允许滚动,默认NO - (BOOL)emptyDataSetShouldAllowScroll:(UIScrollView *)scrollView { return YES; } //图片是否要动画效果,默认NO - (BOOL) emptyDataSetShouldAllowImageViewAnimate:(UIScrollView *)scrollView { return YES; } //空白页点击事件 - (void)emptyDataSetDidTapView:(UIScrollView *)scrollView { } //空白页按钮点击事件 - (void)emptyDataSetDidTapButton:(UIScrollView *)scrollView { }
注: 文章由我们 iOS122(http://www.ios122.com)的小伙伴 @酌晨茗
整理,喜欢就一起参与: iOS122 任务池
0 0
- DZNEmptyDataSet,优秀的空白页或者出错页封装
- 史上最全的DZNEmptyDataSet(空白页框架)说明书
- DZNEmptyDataSet(一个好用的空白页展示第三方)
- DZNEmptyDataSet实现的分析
- DZNEmptyDataSet
- iOS开发-DZNEmptyDataSet的使用
- iOS开发-DZNEmptyDataSet的使用
- DZNEmptyDataSet UItabelView空数据 背景图的实现
- 解决Android首次启动APP时,显示空白页或者黑屏时间长的问题
- 重新生成或者删除出错的IDOC
- 水晶报表按组分页出现空白页的解决方法
- word删除空白页的方法
- 如何成为一个合格的或者优秀的FLASH制作者
- 机械、电子、计算机类优秀的论坛或者网站
- IOS 优秀的封装结构-定义自己的UITableViewCell
- responseXML 为什么为空或者出错?调试这种情况的方法
- 关于 vs2005 添加类或者变量 出错问题的解决方案
- Qt调用MFC的dll或者lib出错
- 创建github仓库后如何推送代码
- linkedList
- iOS设计模式简介
- HDU 2438 Turn the corner
- Python字典的json格式化处理
- DZNEmptyDataSet,优秀的空白页或者出错页封装
- 69. Sqrt(x)
- nginx在windows下配置反向代理
- Android 线程池 工作调度
- codeforces 614B
- android monkey测试
- 异步套接字实现
- 带大家一步一步的封装一个聊天键盘
- [实战] 用数人云,部署弹性 ELK 集群就五步