DZNEmptyDataSet,优秀之空白页或者出错页封装

简介

图片 1

型主页:https://github.com/dzenbot/DZNEmptyDataSet

提醒:主要用来UITableView和UICollectionView,也足以用于UIScrollView,其实要是眼前片个见面就此到空白或者网络发生错页

应用给UIScrollView添加代理方来受页面上加空白页,源码很有修意义

导入工程

自动,

pod 'DZNEmptyDataSet'

手动

https://github.com/dzenbot/DZNEmptyDataSet
下充斥解压,Source文件夹下之文本拖入工程

导入头文件:

#import "UIScrollView+EmptyDataSet.h"

初始化

    @interface MainViewController : UITableViewController <DZNEmptyDataSetSource, DZNEmptyDataSetDelegate>

    - (void)viewDidLoad {
         [super viewDidLoad];

         self.tableView.emptyDataSetSource = self;
         self.tableView.emptyDataSetDelegate = self;

    //这行代码必须加上,可以去除tableView的多余的线,否则会影响美观
         self.tableView.tableFooterView = [UIView new];
    }

满足代理方,可以分别部署,都是可选的

空页图片

    - (UIImage *)imageForEmptyDataSet:(UIScrollView *)scrollView {
    return [UIImage imageNamed:@"empty_placeholder"];
    }

图片的动画效果

    - (CAAnimation *)imageAnimationForEmptyDataSet:(UIScrollView *)scrollView {
    CABasicAnimation *animation = [CABasicAnimation animationWithKeyPath: @"transform"];

    animation.fromValue = [NSValue valueWithCATransform3D:CATransform3DIdentity];
    animation.toValue = [NSValue valueWithCATransform3D:CATransform3DMakeRotation(M_PI_2, 0.0, 0.0, 1.0)];

    animation.duration = 0.25;
    animation.cumulative = YES;
    animation.repeatCount = MAXFLOAT;

    return animation;
    }

题文本,详细描述,富文本样式

    - (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];
    }

要需要无法满足,你得自定义

    - (UIView *)customViewForEmptyDataSet:(UIScrollView *)scrollView {
    //加入你自定义的view
    UIActivityIndicatorView *activityView = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleGray];
    [activityView startAnimating];
    return activityView;
    }

另外急需

    //是否显示空白页,默认YES
    - (BOOL)emptyDataSetShouldDisplay:(UIScrollView *)scrollView {
    return YES;
    }

    //是否允许点击,默认YES
    - (BOOL)emptyDataSetShouldAllowTouch:(UIScrollView *)scrollView {
    return YES;
    }

    //是否允许滚动,默认NO
    - (BOOL)emptyDataSetShouldAllowScroll:(UIScrollView *)scrollView {
    return YES;
    }

    //图片是否要动画效果,默认NO
    - (BOOL) emptyDataSetShouldAllowImageViewAnimate:(UIScrollView *)scrollView {
    return YES;
    }

    //空白页点击事件
    - (void)emptyDataSetDidTapView:(UIScrollView *)scrollView {

    }

    //空白页按钮点击事件
    - (void)emptyDataSetDidTapButton:(UIScrollView *)scrollView {

    }

流动: 文章由我们
iOS122(http://www.ios122.com)的伴%E7%9A%84%E5%B0%8F%E4%BC%99%E4%BC%B4)
@酌晨茗 整理,喜欢就联手与: iOS122
任务池

发表评论

电子邮件地址不会被公开。 必填项已用*标注