DZNEmptyDataSet 表格為空如何顯示圖標

感謝萬能的github

下載地址:DZNEmptyDataSet https://github.com/dzenbot/DZNEmptyDataSet

上效果
首先在你的ViewController里面導入
#import "UIScrollView+EmptyDataSet.h"
遵守 <DZNEmptyDataSetSource, DZNEmptyDataSetDelegate> 協(xié)議

`@interface MainViewController : UITableViewController <DZNEmptyDataSetSource, DZNEmptyDataSetDelegate>

  • (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 實現(xiàn)方法
- (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"];}

返回空白區(qū)域的顏色自定義

- (UIColor *)backgroundColorForEmptyDataSet:(UIScrollView *)scrollView{ return [UIColor whiteColor];}

返回一個自定義的 view

  • (UIView *)customViewForEmptyDataSet:(UIScrollView *)scrollView{ UIActivityIndicatorView *activityView = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleGray]; [activityView startAnimating]; return activityView;}

此外,您還可以調(diào)整垂直對齊的內(nèi)容視圖(即:有用tableHeaderView時可見):

- (CGFloat)verticalOffsetForEmptyDataSet:(UIScrollView *)scrollView{ return -self.tableView.tableHeaderView.frame.size.height/2.0f;}

返回間距離

  • (CGFloat)verticalOffsetForEmptyDataSet:(UIScrollView *)scrollView{ return -self.tableView.tableHeaderView.frame.size.height/2.0f;}

委托實現(xiàn)

要求知道空的狀態(tài)應該渲染和顯示 (Default is YES) :
- (BOOL)emptyDataSetShouldDisplay:(UIScrollView *)scrollView{ return YES;}

是否允許點擊 (默認是 YES) :
- (BOOL)emptyDataSetShouldAllowTouch:(UIScrollView *)scrollView{ return YES;}

是否允許滾動 (默認是 NO) :
- (BOOL)emptyDataSetShouldAllowScroll:(UIScrollView *)scrollView{ return YES;}

空白區(qū)域點擊響應:
- (void)emptyDataSetDidTapView:(UIScrollView *)scrollView{ // Do something}

點擊button 響應
- (void)emptyDataSetDidTapButton:(UIScrollView *)scrollView{ // Do something}

刷新當前表格
[self.tableView reloadData];
或者
[self.collectionView reloadData];

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容