iOS 给tableview添加空态页面

1.导入第三方库

pod 'DZNEmptyDataSet'

2.使用

#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;
}

 

posted on 2017-12-23 21:41  麦芽呀~  阅读(1439)  评论(0编辑  收藏  举报