iOS开发-DZNEmptyDataSet的使用

来源:互联网 发布:漫威电影顺序 知乎 编辑:程序博客网 时间:2024/06/05 18:03

#import "UIScrollView+EmptyDataSet.h"

遵守 协议

`@interface MainViewController : UITableViewController 

(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];

 }

更多数据源

// 提示 标题 title

-(NSAttributedString *)titleForEmptyDataSet:(UIScrollView*)scrollView;

// 提示内容 message

-(NSAttributedString *)descriptionForEmptyDataSet:(UIScrollView*)scrollView;

// 图片 注意大小

-(UIImage *)imageForEmptyDataSet:(UIScrollView*)scrollView;

// 图片 tintColor

-(UIColor *)imageTintColorForEmptyDataSet:(UIScrollView*)scrollView;

// 添加 提示图片的 动画

-(CAAnimation *)imageAnimationForEmptyDataSet:(UIScrollView*)scrollView;

// 按钮文字

-(NSAttributedString *)buttonTitleForEmptyDataSet:(UIScrollView*)scrollViewforState:(UIControlState)state;

// 按钮图片

-(UIImage *)buttonImageForEmptyDataSet:(UIScrollView*)scrollViewforState:(UIControlState)state;

-(UIImage *)buttonBackgroundImageForEmptyDataSet:(UIScrollView*)scrollViewforState:(UIControlState)state;

// 大背景颜色

-(UIColor *)backgroundColorForEmptyDataSet:(UIScrollView*)scrollView;

// 自定义view

-(UIView *)customViewForEmptyDataSet:(UIScrollView*)scrollView;

// 内容偏移

-(CGFloat)verticalOffsetForEmptyDataSet:(UIScrollView*)scrollView;

// 内容间距

-(CGFloat)spaceHeightForEmptyDataSet:(UIScrollView*)scrollView;

更多代理

// 亲测 无效?

-(BOOL)emptyDataSetShouldFadeIn:(UIScrollView*)scrollView;

// 作为背景,YES:一直显示;NO:没数据才显示

-(BOOL)emptyDataSetShouldBeForcedToDisplay:(UIScrollView*)scrollView;

// 是否使用 背景

-(BOOL)emptyDataSetShouldDisplay:(UIScrollView*)scrollView;

// 触摸激活

-(BOOL)emptyDataSetShouldAllowTouch:(UIScrollView*)scrollView;

// 滚动激活

-(BOOL)emptyDataSetShouldAllowScroll:(UIScrollView*)scrollView;

// 动画激活

-(BOOL)emptyDataSetShouldAnimateImageView:(UIScrollView*)scrollView;

// 点击 view

-(void)emptyDataSet:(UIScrollView*)scrollViewdidTapView:(UIView*)view;

// 点击 btn

-(void)emptyDataSet:(UIScrollView*)scrollViewdidTapButton:(UIButton*)button;

-(void)emptyDataSetWillAppear:(UIScrollView*)scrollView;

-(void)emptyDataSetDidAppear:(UIScrollView*)scrollView;

-(void)emptyDataSetWillDisappear:(UIScrollView*)scrollView;

-(void)emptyDataSetDidDisappear:(UIScrollView*)scrollView;

demo下载:  https://github.com/13662049573/DZNEmptyDataSe- 

原创粉丝点击