DZNEmptyDataSet空白数据集显示框架简单使用

//

//  ViewController2.m

//  TestTD

//

//  Created by Mac on 2017/6/24.

//  Copyright © 2017 MLBiMAC. All rights reserved.

//


#import "ViewController2.h"


#import "UIScrollView+EmptyDataSet.h"


#define kScreenW [UIScreen mainScreen].bounds.size.width

#define kScreenH [UIScreen mainScreen].bounds.size.height


@interface ViewController2 ()<UITableViewDelegate,UITableViewDataSource,DZNEmptyDataSetSource,DZNEmptyDataSetDelegate>

@property (nonatomic,strong)UITableView *tableView;

@property (nonatomic,getter=isLoading)BOOL loading;


@end


@implementation ViewController2


- (void)viewDidLoad {

    [super viewDidLoad];

    self.automaticallyAdjustsScrollViewInsets =NO;

    self.view.backgroundColor = [UIColorwhiteColor];

    

    self.tableView.emptyDataSetSource = self;

    self.tableView.emptyDataSetDelegate = self;

    

}


-(UITableView *)tableView{

    if (!_tableView) {

        _tableView = [[UITableViewalloc]initWithFrame:CGRectMake(0,64,kScreenW, kScreenH -64)style:UITableViewStylePlain];

        _tableView.delegate = self;

        _tableView.dataSource = self;

        [self.viewaddSubview:_tableView];

        _tableView.tableFooterView = [[UITableViewalloc]initWithFrame:CGRectZero];

    }

    return _tableView;

}


-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{

    return 0;

}


-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{

    staticNSString *identifier =@"cell";

    UITableViewCell *cell = [tableViewdequeueReusableCellWithIdentifier:identifier];

    if (!cell) {

        cell = [[UITableViewCellalloc]initWithStyle:UITableViewCellStyleDefaultreuseIdentifier:identifier];

    }

    

    cell.textLabel.text = [NSStringstringWithFormat:@"%ld",indexPath.row];

    

    return cell;

}

/*

//返回单张图片

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

    return [UIImage imageNamed:@"empty_placeholder"];

}

 */

//空白页显示图片

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

    if (self.isLoading) {

        // 圆形加载图片

        return [UIImageimageNamed:@"loading_imgBlue_78x78"];

    }else {

        // 默认静态图片

        return [UIImageimageNamed:@"empty_placeholder"];

    }

}



//返回标题

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

    NSString *text =@"没有数据了!";

    return [[NSAttributedStringalloc]initWithString:textattributes:nil ];

}

//返回详情

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

    NSString *text =@"没有数据了!ahahahaahhaahahahahahahahahaha.";

    NSMutableParagraphStyle *paragraph = [NSMutableParagraphStylenew];

    paragraph.lineBreakMode =NSLineBreakByWordWrapping;

    paragraph.alignment =NSTextAlignmentCenter;

    NSDictionary *attributes =@{NSFontAttributeName: [UIFontsystemFontOfSize:15.0f],NSForegroundColorAttributeName: [UIColorlightGrayColor],NSParagraphStyleAttributeName: paragraph};

    return [[NSAttributedStringalloc]initWithString:textattributes:attributes];

}


//返回可以点击的按钮上面带文字

- (NSAttributedString *)buttonTitleForEmptyDataSet:(UIScrollView *)scrollView forState:(UIControlState)state{

    NSDictionary *attributes =@{NSFontAttributeName: [UIFontboldSystemFontOfSize:17.0f]};

    return [[NSAttributedStringalloc]initWithString:@"点击刷新"attributes:attributes];

}

/*

//返回可以点击的按钮上面带图片

- (UIImage *)buttonImageForEmptyDataSet:(UIScrollView *)scrollView forState:(UIControlState)state{

    return [UIImage imageNamed:@"search_icon"];

}

 */

//返回空白区域的颜色自定义

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

}

- (void)emptyDataSetDidTapButton:(UIScrollView *)scrollView{

    NSLog(@"啦啦啦");

    // 空白页面被点击时开启动画,reloadEmptyDataSet

    self.loading =YES;

    dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(3.0 *NSEC_PER_SEC)),dispatch_get_main_queue(), ^{

        // 关闭动画,reloadEmptyDataSet

        self.loading =NO;

    });

}


//图像视图动画:旋转

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

{

    CABasicAnimation *animation = [CABasicAnimationanimationWithKeyPath:@"transform"];

    

    animation.fromValue = [NSValuevalueWithCATransform3D:CATransform3DIdentity];

    animation.toValue = [NSValuevalueWithCATransform3D:CATransform3DMakeRotation(M_PI_2,0.0,0.0, 1.0)];

    

    animation.duration =0.25;

    animation.cumulative =YES;

    animation.repeatCount =MAXFLOAT;

    

    return animation;

}

/*

//图像视图动画

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

{

    CABasicAnimation *animation = [CABasicAnimation animationWithKeyPath:@"bounds"];

    animation.duration = 1.25;

    animation.cumulative = NO;

    animation.repeatCount = MAXFLOAT;

    animation.toValue = [NSValue valueWithCGRect:CGRectMake(0, 0, 45, 45)];

    

    return animation;

}

// 向代理请求图像视图动画权限。默认值为NO

// 确保从 imageAnimationForEmptyDataSet返回有效的CAAnimation对象:

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

    return YES;

}

*/

//是否开启动画

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

    return self.isLoading;

}

- (void)didReceiveMemoryWarning {

    [super didReceiveMemoryWarning];

    // Dispose of any resources that can be recreated.

}


//空白页面被点击时刷新页面

- (void)emptyDataSet:(UIScrollView *)scrollView didTapView:(UIView *)view {

    // 空白页面被点击时开启动画,reloadEmptyDataSet

    self.loading =YES;

    dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(3.0 *NSEC_PER_SEC)),dispatch_get_main_queue(), ^{

        // 关闭动画,reloadEmptyDataSet

        self.loading =NO;

    });

}


//为该属性设置 setter方法,重新加载空数据集视图:

- (void)setLoading:(BOOL)loading

{

    if (self.isLoading == loading) {

        return;

    }

    

    _loading = loading;

    

    [self.tableViewreloadEmptyDataSet];

}

 

/*

#pragma mark - Navigation


// In a storyboard-based application, you will often want to do a little preparation before navigation

- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {

    // Get the new view controller using [segue destinationViewController].

    // Pass the selected object to the new view controller.

}

*/


@end

深入了解进入github

https://github.com/dzenbot/DZNEmptyDataSet




  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值