Skip to content

Repository files navigation

FORScrollViewEmptyAssistant

CI StatusVersionLicensePlatform

ScreenShot

Example

To run the example project, clone the repo, and run pod install from the Example directory first.

block config

// easy emptyview's layout
[self.tableview emptyViewConfigerBlock:^(FOREmptyAssistantConfiger *configer) {
configer.emptyTitle = @"Hello World";
configer.emptySubtitle = @"Talk is cheap. Show me the code";
configer.emptyImage = [UIImage imageNamed:@"image_empty"];
}];
// complicated typeof(self) weakSelf = self;
[self.tableview emptyViewConfigerBlock:^(FOREmptyAssistantConfiger *configer) {
configer.emptyTitle = @"Hello World";
configer.emptySubtitle = @"Talk is cheap. Show me the code";
configer.emptyImage = [UIImage imageNamed:@"image_empty"];
configer.imageAnimation = imageAnimation;
configer.emptyBtnTitle = @"Request Net";
configer.emptyBtnClickBlock = ^{
[weakSelf.tableview.mj_header beginRefreshing];
};
}];

custom view as emptyView

typeof(self) weakSelf = self;
FOREmptyAssistantConfiger *configer = [FOREmptyAssistantConfiger new];
configer.emptyTitle = @"This is demo";
configer.emptySubtitle = @"tap this to request network \n hurry up";
configer.emptyViewTapBlock = ^{
[weakSelf.tableview.mj_header beginRefreshing];
};
[self.tableview emptyViewConfiger:configer];

custom view as emptyView

 UIView *customView = [[[NSBundlemainBundle] loadNibNamed:@"FORCustomCell"owner:niloptions:nil] firstObject];
FOREmptyAssistantConfiger *configer = [FOREmptyAssistantConfiger new];
configer.customView = customView;
[self.tableview emptyViewConfiger:configer];

Requirements

**声明:**本库是基于DZNEmptyDataSet的基础上做的封装,目的就是:

  • 简易使用于TableView和CollectionView上
  • 改进灵活度,根据不同状态切换不同的空白页(例如:网络失败 / 请求成功的空数据)。

说明:DZNEmptyDataSet及本库的封装都是基于dataSource的array数组为空时才回展示,更确切的说是cell的个数为零。

**提醒:**除了TableView和CollectionView初始化不需要reload,其他情况下数据为空时需要触发reloadData方法来呈现空白页占位图,内部swizzle了reloadData方法。

TableView几乎在所有的项目中都需要用到,那呈现出的空数据或者网络连接失败状态下的TableView或CollectionView要是没有做相对应的说明,使用者很容易会迷惑甚至不知所措,并且大量的列表存在为空的可能性时需要我们做大量的配置也是一件很繁琐的事情,这就是这个库要解决的问题

使用空白页占位图的优点

  • 避免了一整片空白的视图,解释为什么当前空白页是这样的
  • 可以添加一些交互回调事件
  • 避免强类型提示的突兀出现(UIAlerView、HUDProgress等等)
  • 更快引导用户入门
  • 使用logo加深品牌的影响

特征

  • >= iOS6.0
  • iPhone 和 iPad
  • 限于在TableView和CollectionView上使用
  • 对应元素一共有emptyImage、emptyTitle、emptySubtitle、emptyButton
  • 支持自动布局及屏幕旋转(Autolayout)
  • 可调整一些属性包括:
属性类型说明默认值
DataSource
emptyTitleNSString标题@""
emptyTitleFontUIFont标题字体systemFontOfSize:17.0f
emptyTitleColorUIColor标题颜色darkGrayColor
emptySubtitleNSString副标题@""
emptySubtitleFontUIFont副标题字体systemFontOfSize:15.0f
emptySubtitleColorUIColor副标题颜色lightGrayColor
emptyImageUIImage空白页占位图nil
emptyBtnTitleNSString按钮标题@""
emptyBtntitleFontUIFont按钮字体systemFontOfSize:17.0f
emptyBtnTitleColorUIColor按钮标题颜色whiteColor
emptyBtnImageUIImage按钮iconnil
emptyBtnBackgroundImageUIImage按钮背景图片blank_button
customViewUIView自定义空白view(则前面设置的样式全部失效)nil
emptyVerticalOffsetCGFloat空白页整体位置默认是在tableView居中显示0
emptySpaceHeightCGFloat空白页的图片、按钮、文案之间的间距大小20
Delegate
allowScrollBOOL添加空白页后ScrollView是否可以继续拖拽YES
userInteractionEnabledBOOL可交互YES
shouldDisplayBOOL(^)()添加空白页后ScrollView是否可以展示YES
shouldStartImageViewAnimateBOOL(^)()空白页的图片是否执行动画YES
imageAnimationCAAnimation图片的动画, Note: shouldStartAnimate==NO
emptyViewTapBlockvoid(^)()空白页区域点击/
emptyBtnClickBlockvoid(^)()按钮点击/
Life Cirlce
emptyViewWillAppearvoid(^)()life cricle/
emptyViewWillDisappearvoid(^)()life cricle/
emptyViewDidAppearvoid(^)()life cricle/
emptyViewDidDisappearvoid(^)()life cricle/

Installation

FORScrollViewEmptyAssistant is available through CocoaPods. To install it, simply add the following line to your Podfile:

pod'FORScrollViewEmptyAssistant'

Author

XcodeYang, xcodeyang@gmail.com

License

FORScrollViewEmptyAssistant is available under the MIT license. See the LICENSE file for more info.

About

UITableView/UICollectionView superclass for showing empty datasets whenever the view has no content to display

Resources

Stars

58 stars

Watchers

2 watching

Forks

Releases

Packages

Contributors

Languages