简介

项目主页: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,优秀的空白页或者出错页封装的更多相关文章

  1. vs 2015 "加载该页时出错。" 解决方案

    错误信息: 加载该页时出错. 未找到与约束   ContractName Microsoft.CodeAnalysis.Editor.TypeScript.ScriptContexts.ITypeSc ...

  2. Visual Studio《加载此属性页时出错》的解决办法

    打开aspx页面时不能切换到设计视图,vs 2008工具箱中无控件.打开vs 2008的工具>选项>HTML设计器时提示:加载此属性页时出错 有时还会有其它错误提示,比如打开一个Windo ...

  3. 503是一种HTTP状态码。英文名503 Service Unavailable与404(404 Not Found)是同属一种网页状态出错码。前者是服务器出错的一种返回状态,后者是网页程序没有相关的结果后返回的一种状态,需要优化网站的时候通常需要制作404出错页以便网站整体优化。

    goldCat1 商城 消息 | 百度首页 新闻网页贴吧知道音乐图片视频地图百科文库 进入词条搜索词条帮助 近期有不法分子冒充官方收费编辑词条,百度百科严正声明:百科词条人人可编辑,词条创建和修改均免 ...

  4. 【Itext】7步制作Itext5页眉页脚pdf实现第几页共几页

    itext5页眉页脚工具类,实现page x of y 完美兼容各种格式大小文档A4/B5/B3,兼容各种文档格式自动计算页脚XY轴坐标 鉴于没人做的这么细致,自己就写了一个itext5页眉页脚工具类 ...

  5. 用Flutter开发的跨平台项目,完美运行在Android和IOS上,Material简洁风格,包括启动页、引导页、注册、登录、首页、体系、公众号、导航、项目,还有漂亮的妹子图库,运行极度流畅,结构清晰,代码规范,值得拥有

    Flutter学习资源汇总持续更新中...... Flutter官方网站 Flutter中文网 wendux的Flutter实战 Flutter官方exampleflutter_gallery 阿里巴 ...

  6. C# 给现有PDF文档添加页眉、页脚

    概述 页眉页脚是一篇完整.精致的文档的重要组成部分.在页眉页脚处,可以呈现的内容很多,如公司名称.页码.工作表名.日期.图片,如LOGO.标记等.在之前的文章中介绍了如何通过新建一页空白PDF页来添加 ...

  7. 移动站适配rel=alternate PC页和H5页适配标注

    鉴于移动化大潮的汹涌和H5页的炫丽普及,百度针对PC页与H5页的跳转适配方式推出了最优方案:1.在pc版网页上,添加指向对应移动版网址的特殊链接rel="alternate"标记, ...

  8. GridView利用PagerTemplate做分页显示设置上一页下一页转到下拉转页

    效果如图: 代码如下: aspx页: <asp:GridView ID="GridViewMain" runat="server" OnPageIndex ...

  9. NCreport报表控件教程:设计页眉和页脚

    一.设计页眉 一般来说页眉部分一般是用于包含标题的内容, 首先我们会添加列标签到页眉部分,标签都是简单的文本,标签项一般是用于在报表上显示一些描述信息,标签都是静态项,所以它们的值不会有变化. 添加标 ...

随机推荐

  1. Meaningful Use 中与HL7相关的消息及医疗文档

    汇总 HL7 消息 入出转消息 ADT A01,A03,A04,A08 免疫消息 VXU V04 电子处方消息 NEWRX Message v8.1 EDIFACT, v8.1 XML,  v10.6 ...

  2. Android开发之蓝牙 --修改本机蓝牙设备的可见性,并扫描周围可用的蓝牙设备

    一. 修改本机蓝牙设备的可见性 二. 扫描周围可用的蓝牙设备 一.  清单文件AdroidManifest.xml: <uses-permission android:name="an ...

  3. Codeforces Round #292 (Div. 1) B. Drazil and Tiles 拓扑排序

    B. Drazil and Tiles 题目连接: http://codeforces.com/contest/516/problem/B Description Drazil created a f ...

  4. Microsoft Fakes

    http://baike.baidu.com/view/9602275.htm?fr=aladdin http://technet.microsoft.com/zh-cn/magazine/hh549 ...

  5. 关于execel单元格中的数字变成文本(左上角带绿色三角形标志)的办法

    对于很多软件,需要将数字变成文本,才能导入到该系统当中.在excel当中,如果数字是以文本的形式存储,在左上角是带有绿色的三角形标志的.如果对于大批量数据,操作方法如下:1将目标列数据copy到记事本 ...

  6. 在Window下安装Oracle 12C Cloud Control Agent

    ① 准备好安装源,这个ORACLE普通账号无法下载到,有需要的可以联系我   p14570373_112000_Generic.zip,用于Windows 64位操作系统 ② 解压p14570373_ ...

  7. ECshop设置301最快捷最简单的方法

    ECshop设置301最快捷最简单的方法 在 init.php中加入以下代码 if (strtolower($_SERVER['SERVER_NAME'])!='www.fz1688.com') { ...

  8. 【jquery】jquery.cookie.js 的使用指南

    之前有写过一篇原生 js 的 cookie 介绍,并且最后封装成 cookie.js 具体内容点击传送门. jquery.cookie.js 是一款轻量级的 cookie 插件,可以读取,写入和删除 ...

  9. Android手机的 storage

    老外的一段解释 -------------------------------------------------------------------------------------------- ...

  10. 聊聊 Linux 中的五种 IO 模型

    本文转载自: http://mp.weixin.qq.com/s?__biz=MzAxODI5ODMwOA==&mid=2666538919&idx=1&sn=6013c451 ...