DZNEmptyDataSet,优秀的空白页或者出错页封装
简介

项目主页: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 任务池
DZNEmptyDataSet,优秀的空白页或者出错页封装的更多相关文章
- vs 2015 "加载该页时出错。" 解决方案
		
错误信息: 加载该页时出错. 未找到与约束 ContractName Microsoft.CodeAnalysis.Editor.TypeScript.ScriptContexts.ITypeSc ...
 - Visual Studio《加载此属性页时出错》的解决办法
		
打开aspx页面时不能切换到设计视图,vs 2008工具箱中无控件.打开vs 2008的工具>选项>HTML设计器时提示:加载此属性页时出错 有时还会有其它错误提示,比如打开一个Windo ...
 - 503是一种HTTP状态码。英文名503 Service Unavailable与404(404 Not Found)是同属一种网页状态出错码。前者是服务器出错的一种返回状态,后者是网页程序没有相关的结果后返回的一种状态,需要优化网站的时候通常需要制作404出错页以便网站整体优化。
		
goldCat1 商城 消息 | 百度首页 新闻网页贴吧知道音乐图片视频地图百科文库 进入词条搜索词条帮助 近期有不法分子冒充官方收费编辑词条,百度百科严正声明:百科词条人人可编辑,词条创建和修改均免 ...
 - 【Itext】7步制作Itext5页眉页脚pdf实现第几页共几页
		
itext5页眉页脚工具类,实现page x of y 完美兼容各种格式大小文档A4/B5/B3,兼容各种文档格式自动计算页脚XY轴坐标 鉴于没人做的这么细致,自己就写了一个itext5页眉页脚工具类 ...
 - 用Flutter开发的跨平台项目,完美运行在Android和IOS上,Material简洁风格,包括启动页、引导页、注册、登录、首页、体系、公众号、导航、项目,还有漂亮的妹子图库,运行极度流畅,结构清晰,代码规范,值得拥有
		
Flutter学习资源汇总持续更新中...... Flutter官方网站 Flutter中文网 wendux的Flutter实战 Flutter官方exampleflutter_gallery 阿里巴 ...
 - C# 给现有PDF文档添加页眉、页脚
		
概述 页眉页脚是一篇完整.精致的文档的重要组成部分.在页眉页脚处,可以呈现的内容很多,如公司名称.页码.工作表名.日期.图片,如LOGO.标记等.在之前的文章中介绍了如何通过新建一页空白PDF页来添加 ...
 - 移动站适配rel=alternate PC页和H5页适配标注
		
鉴于移动化大潮的汹涌和H5页的炫丽普及,百度针对PC页与H5页的跳转适配方式推出了最优方案:1.在pc版网页上,添加指向对应移动版网址的特殊链接rel="alternate"标记, ...
 - GridView利用PagerTemplate做分页显示设置上一页下一页转到下拉转页
		
效果如图: 代码如下: aspx页: <asp:GridView ID="GridViewMain" runat="server" OnPageIndex ...
 - NCreport报表控件教程:设计页眉和页脚
		
一.设计页眉 一般来说页眉部分一般是用于包含标题的内容, 首先我们会添加列标签到页眉部分,标签都是简单的文本,标签项一般是用于在报表上显示一些描述信息,标签都是静态项,所以它们的值不会有变化. 添加标 ...
 
随机推荐
- java产生随机数的几种方式
			
java产生随机数的几种方式 一.在j2se里我们可以使用Math.random()方法来产生一个随机数,这个产生的随机数是0-1之间的一个double,我们可以把他乘以一定的数,比如说乘以100,他 ...
 - 用 Mahout 和 Elasticsearch 实现推荐系统
			
原文地址 本文内容 软件 步骤 控制相关性 总结 参考资料 本文介绍如何用带 Apache Mahout 的 MapR Sandbox for Hadoop 和 Elasticsearch 搭建推荐引 ...
 - Python中import的使用
			
python中的import语句是用来导入模块的,在python模块库中有着大量的模块可供使用,要想使用这些文件需要用import语句把指定模块导入到当前程序中. import语句的作用 import ...
 - phpStorm无法使用svn1.8的解决办法
			
1.安装SVN的Command Lines Tools. 2.在phpStorm的SVN属性中,将Use Command Line Client填入:C:\Program Files\Tortoise ...
 - [Scheme]一个Scheme的Metacircular evaluator
			
这个解释器可以用来跑前面两篇文章的例子,所以一并扔出来,三部曲哈哈. Lisp内置的S-expression相当于解析好的语法树,而借助quasiquote和unquote又很容易进行语法树层面的变换 ...
 - [Compose] 21. Apply Natural Transformations in everyday work
			
We see three varied examples of where natural transformations come in handy. const Right = x => ( ...
 - 2015.10.14-TransactionScope测试
			
测试代码: ; ; List<string> lst = null; Action doSth = () => { using (var db = new TestSystemEnt ...
 - 我的web框架
			
我的web框架 ========================================================== 前端:css(bootstrap,自己的代码片段),js(jque ...
 - MassTransit RabbitMQ 参考文档
			
Autofac http://docs.autofac.org/en/latest/lifetime/startup.html RabbitMQ http://www.rabbitmq.com/dot ...
 - 并行编程多线程之Parallel
			
1.简介 随着多核时代的到来,并行开发越来越展示出它的强大威力!使用并行程序,充分的利用系统资源,提高程序的性能.在.net 4.0中,微软给我们提供了一个新的命名空间:System.Threadin ...