No data, no network view

1.No data.h

#import <UIKit/UIKit.h>

typedef void(^refreshBlock)(void);
@interface STNoDataView : UIView
@property (strong, nonatomic) UILabel *detailLabel;
@property (nonatomic,strong)  UIImageView * imageView;
@property (nonatomic, strong) NSLayoutConstraint *imageTop;
@property (copy, nonatomic) refreshBlock refreshBlock;
- (instancetype)initIsCell:(BOOL)isCell;
@end
  1. No data .m
#import "STNoDataView.h"
//#import "UIColor+Additions.h"
//#import "Lyt.h"
//#import "UILabel+lyt.h"
//#import "UIImageView+lyt.h"
//#import "UIButton+lyt.h"

@interface STNoDataView()


@end

@implementation STNoDataView

- (instancetype)init
{
    self = [super initWithFrame:CGRectZero];
    if (self) {
        [self configUI:NO];
    }
    return self;
}

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        [self configUI:NO];
    }
    return self;
}

- (instancetype)initIsCell:(BOOL)isCell
{
    self = [super initWithFrame:CGRectZero];
    if (self) {
        [self configUI:isCell];
    }
    return self;
}

- (void)configUI:(BOOL)isCell
{
    [self addSubview:self.imageView];
    [self addSubview:self.detailLabel];
    self.imageView.image = ImageNamed(@"table_nodata");
    [self.imageView mas_updateConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(self.mas_centerY).offset(isCell?0:-141*WIDTHRADIUS);
        make.centerX.equalTo(self.mas_centerX);
        make.size.mas_offset(CGSizeMake(200*WIDTHRADIUS, 141*WIDTHRADIUS));
    }];
    [self.detailLabel mas_updateConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.imageView.mas_bottom).offset(20*WIDTHRADIUS);
        make.centerX.equalTo(self.mas_centerX);
    }];
    self.backgroundColor = Color_TableView_Background;
    UITapGestureRecognizer *gesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(reloadAction)];
    [self addGestureRecognizer:gesture];
    }

-(UIImageView *)imageView{
    if (!_imageView) {
        _imageView = [XWTool imageName:ImageNamed(@"") SuperView:nil];
    }
    return _imageView;
}
-(UILabel *)detailLabel{
    if (!_detailLabel) {
        _detailLabel = [XWTool lblTitile:@"暂无数据哦~" font:13 textColor:Color_Title_666 SuperView:nil];
        _detailLabel.numberOfLines = 0;
        _detailLabel.textAlignment = NSTextAlignmentCenter;
    }
    return _detailLabel;
}


- (void) reloadAction
{
    if (self.refreshBlock) {
        self.refreshBlock();
    }
}
@end

3.No network.h

#import <UIKit/UIKit.h>

@interface STNoNetReloadView : UIView

@property (strong, nonatomic) UILabel *detailLabel;
//
//@property (nonatomic, retain) UILabel *reloadBtn;

@property (nonatomic, retain) UIImageView *nonetView;

@property (copy, nonatomic) dispatch_block_t btnClick;

@end

4.No network.m

#import "STNoNetReloadView.h"
//#import "UIImageView+lyt.h"
//#import "Lyt.h"
//#import "UILabel+lyt.h"

@interface STNoNetReloadView()


@end

@implementation STNoNetReloadView

- (instancetype)init
{
    self = [super initWithFrame:CGRectZero];
    if (self) {
        [self configUI];
        
    }
    return self;
}

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        [self configUI];
    }
    return self;
}

- (void)configUI
{
//    __weak typeof(self) weakSelf = self;
    [self addSubview:self.nonetView];
    [self addSubview:self.detailLabel];
    [self.nonetView mas_updateConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(self.mas_centerY).offset(-150*WIDTHRADIUS);
        make.centerX.equalTo(self.mas_centerX);
        make.size.mas_offset(CGSizeMake(166*WIDTHRADIUS, 150*WIDTHRADIUS));
    }];
    [self.detailLabel mas_updateConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.nonetView.mas_bottom).offset(20*WIDTHRADIUS);
        make.centerX.equalTo(self.mas_centerX);
    }];
//    _nonetView = [UIImageView getImageViewWithImageName:@"table_nonet" superView:self lytSet:^(UIImageView *imageView) {
//        [imageView lyt_centerXInParent];
//        [imageView lyt_alignTopToParentWithMargin:162 * WIDTHRADIUS];
//        [imageView lyt_setSize:CGSizeMake(108 * WIDTHRADIUS, 87 * WIDTHRADIUS)];
//    }];
//
//    _tipLabel = [UILabel getLabelWithFontSize:13 textColor:Color_Title superView:self lytSet:^(UILabel *label) {
//        [label lyt_centerXInParent];
//        [label lyt_placeBelowView:weakSelf.nonetView margin:19 * WIDTHRADIUS];
//    }];
//    _tipLabel.text = @"无网络信号";
    
    self.backgroundColor = Color_TableView_Background;
//    _reloadBtn = [UILabel getLabelWithFontSize:15 textColor:Color_Content superView:self lytSet:^(UILabel *label) {
//        [label lyt_centerXInParent];
//        [label lyt_placeBelowView:weakSelf.tipLabel margin:22 * WIDTHRADIUS];
//    }];
//    _reloadBtn.text = @"请检查网络是否正常后,点屏幕重试";
    
    UITapGestureRecognizer *gesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(reloadAction)];
    [self addGestureRecognizer:gesture];
}

-(UIImageView *)nonetView{
    if (!_nonetView) {
        _nonetView = [XWTool imageName:ImageNamed(@"table_nonet") SuperView:nil];
    }
    return _nonetView;
}
-(UILabel *)detailLabel{
    if (!_detailLabel) {
        _detailLabel = [XWTool lblTitile:@"网络丢失啦,试试点击屏幕重新加载~" font:13 textColor:Color_Title_666 SuperView:nil];
        _detailLabel.numberOfLines = 0;
        _detailLabel.textAlignment = NSTextAlignmentCenter;
    }
    return _detailLabel;
}
- (void) reloadAction
{
    if (_btnClick) {
        _btnClick();
    }
}

@end

Guess you like

Origin blog.csdn.net/weixin_42050662/article/details/122734516