iOS 給tableview添加空態頁面

1.導入第三方庫app

pod 'DZNEmptyDataSet'

2.使用spa

#import <DZNEmptyDataSet/UIScrollView+EmptyDataSet.h>
DZNEmptyDataSetSource, DZNEmptyDataSetDelegate
//空數據空白
    self.tableView.emptyDataSetSource = self;
    self.tableView.emptyDataSetDelegate = self;
#pragma mark -- DZNEmptyDataSetSource

- (NSAttributedString *)descriptionForEmptyDataSet:(UIScrollView *)scrollView {
    NSString *text = @"暫無未讀消息";
    NSMutableParagraphStyle *paragraph = [NSMutableParagraphStyle new];
    paragraph.lineBreakMode = NSLineBreakByWordWrapping;
    paragraph.alignment = NSTextAlignmentCenter;
    NSDictionary *attributes = @{
                                 NSFontAttributeName:[UIFont systemFontOfSize:14],
                                 NSForegroundColorAttributeName:UIColorFromRGB(0xB8B8B8),
                                 NSParagraphStyleAttributeName:paragraph
                                 };
    return [[NSAttributedString alloc] initWithString:text attributes:attributes];
}

- (CGFloat)spaceHeightForEmptyDataSet:(UIScrollView *)scrollView {
    return 25.0f;
}

//往上偏移64高度
- (CGFloat)verticalOffsetForEmptyDataSet:(UIScrollView *)scrollView {
    return -64;
}
相關文章
相關標籤/搜索