NoDataView.m 2.91 KB
//
//  NoDataView.m
//  CNLiveScioLive
//
//  Created by CNLive-zxw on 2018/9/21.
//  Copyright © 2018年 CNLive. All rights reserved.
//

#import "NoDataView.h"

@interface NoDataView()
@property (nonatomic, strong) UIImageView *noImage;
@property (nonatomic, strong) UILabel *noTitle;
@property (nonatomic, strong) UIButton *clickedBtn;

@end
@implementation NoDataView
- (instancetype)initWithFrame:(CGRect)frame{
    self = [super initWithFrame:frame];
    if(self){
        [self setUpUI];
    }
    return self;
    
}
- (void)setImage:(NSString *)image{
    _noImage.hidden = NO;
    _image = image;
    _noImage.image = [UIImage imageNamed:image];
}
- (void)setTitle:(NSString *)title{
    _noTitle.hidden = NO;
    _title = title;
    _noTitle.text = title;
}
- (void)setBtnTitle:(NSString *)btnTitle{
    _clickedBtn.hidden = NO;
    _btnTitle = btnTitle;
    [_clickedBtn setTitle:btnTitle forState:UIControlStateNormal];

}
- (void)setUpUI{
    self.noImage = [[UIImageView alloc] init];
    _noImage.contentMode = UIViewContentModeCenter;
    _noImage.backgroundColor = [UIColor blueColor];
    _noImage.layer.masksToBounds = YES;
    _noImage.userInteractionEnabled = YES;
    _noImage.hidden = YES;
    [self addSubview:_noImage];
    
    self.noTitle = [[UILabel alloc] init];
    _noTitle.numberOfLines = 1;
    _noTitle.textColor = HEXCOLOR(0x333333);
    _noTitle.textAlignment = NSTextAlignmentCenter;
    _noTitle.font = [UIFont systemFontOfSize:18];
    _noTitle.hidden = YES;
    [self addSubview:_noTitle];
    
    self.clickedBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    [_clickedBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    _clickedBtn.titleLabel.font = [UIFont systemFontOfSize:14];
    _clickedBtn.layer.borderColor = [UIColor whiteColor].CGColor;
    _clickedBtn.layer.borderWidth = 1;
    _clickedBtn.layer.cornerRadius = 5;
    _clickedBtn.layer.masksToBounds = YES;
    _clickedBtn.backgroundColor = Color_Blue;
    _clickedBtn.hidden = YES;
    [_clickedBtn addTarget:self action:@selector(clickedLoadingBtn) forControlEvents:UIControlEventTouchUpInside];
    [self addSubview:self.clickedBtn];
    
}
- (void)layoutSubviews{
    
    [_noTitle mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(self.mas_centerX);
        make.centerY.equalTo(self.mas_centerY);

    }];
    
    [_noImage mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.equalTo(self->_noTitle.mas_top).with.offset(-20);
        make.centerX.equalTo(self.mas_centerX);
        make.width.offset(200);
        make.height.offset(200);
    }];

    [_clickedBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self->_noTitle.mas_bottom).with.offset(20);
        make.centerX.equalTo(self.mas_centerX);
        make.width.offset(100);
        make.height.offset(40);

    }];
    
}
- (void)clickedLoadingBtn{
    self.block?self.block():@"";
    
}

@end