LVCRequestFailedView.m 1.94 KB
//
//  LVCRequestFailedView.m
//  LiveVideoCloud
//
//  Created by iOS on 17/3/30.
//  Copyright © 2017年 cnlive. All rights reserved.
//

#import "LVCRequestFailedView.h"

@interface LVCRequestFailedView ()<UIGestureRecognizerDelegate>
{
    NSString *_text;
}

@property (nonatomic, strong) UIImageView *imageView;
@property (nonatomic, strong) UILabel *textLab;
@property (nonatomic, strong) UITapGestureRecognizer *singleTap;    //单击手势

@end

@implementation LVCRequestFailedView

- (instancetype)initWithFrame:(CGRect)frame words:(NSString *)text
{
    self = [super initWithFrame:frame];
    if (self) {
        _text = text;
        [self addSubview:self.imageView];
        [self addSubview:self.textLab];
        [self addGestureRecognizer:self.singleTap];
    }
    return self;
}

- (void)singleTapView
{
    self.hidden = YES;
    if (self.delegate && [self.delegate respondsToSelector:@selector(reloadDataWithView:)]) {
        [self.delegate reloadDataWithView:self];
    }
}

#pragma mark -
#pragma mark - getter
- (UIImageView *)imageView
{
    if (!_imageView) {
        _imageView = [[UIImageView alloc] initWithFrame:CGRectMake(self.width-(self.width*0.25)/2, self.height*0.2, self.width*0.25, self.width*0.25)];
        _imageView.image = [UIImage imageNamed:@"warn"];
        _imageView.center = self.center;
    }
    return _imageView;
}

- (UILabel *)textLab
{
    if (!_textLab) {
        _textLab = [[UILabel alloc] initWithFrame:CGRectMake(0, _imageView.bottom+20, self.width, 20)];
        _textLab.text = _text;
        _textLab.textAlignment = NSTextAlignmentCenter;
        _textLab.textColor = [UIColor lightGrayColor];
        _textLab.font = [UIFont systemFontOfSize:15];
    }
    return _textLab;
}

- (UITapGestureRecognizer *)singleTap
{
    if (!_singleTap) {
        _singleTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(singleTapView)];
        _singleTap.delegate = self;
    }
    return _singleTap;
}
@end