标签:
给大家推荐一个设置页面加载失败时显示加载失败等的框架。
下载地址:DZNEmptyDataSet https://github.com/dzenbot/DZNEmptyDataSet
上效果
首先在你的ViewController里面导入#import "UIScrollView+EmptyDataSet.h"
遵守 <DZNEmptyDataSetSource, DZNEmptyDataSetDelegate> 协议
`@interface MainViewController : UITableViewController <DZNEmptyDataSetSource, DZNEmptyDataSetDelegate>
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]; }
- (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];}
- (CGFloat)verticalOffsetForEmptyDataSet:(UIScrollView *)scrollView{ return -self.tableView.tableHeaderView.frame.size.height/2.0f;}
要求知道空的状态应该渲染和显示 (Default is YES) :- (BOOL)emptyDataSetShouldDisplay:(UIScrollView *)scrollView{ return YES;}
是否允许点击 (默认是 YES) :- (BOOL)emptyDataSetShouldAllowTouch:(UIScrollView *)scrollView{ return YES;}
是否允许滚动 (默认是 NO) :- (BOOL)emptyDataSetShouldAllowScroll:(UIScrollView *)scrollView{ return YES;}
空白区域点击响应:- (void)emptyDataSetDidTapView:(UIScrollView *)scrollView{ // Do something}
点击button 响应- (void)emptyDataSetDidTapButton:(UIScrollView *)scrollView{ // Do something}
刷新当前表格[self.tableView reloadData];
或者[self.collectionView reloadData];
标签:
原文地址:http://www.cnblogs.com/Hakim/p/DZNEmptyDataSet.html