// // TFEmptyBaseView.m // WXReader // // Created by 谢腾飞 on 2020/11/20. // Copyright © 2020 xtfei_2011@126.com. All rights reserved. // #import "TFEmptyBaseView.h" @interface TFEmptyBaseView () @end @implementation TFEmptyBaseView - (instancetype)init { if (self = [super init]) { self.autoShowEmptyView = YES; [self prepare]; } return self; } - (void)prepare { self.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight; } - (void)layoutSubviews { [super layoutSubviews]; UIView *view = self.superview; if (view && [view isKindOfClass:[UIView class]]){ self.xtfei_width = view.xtfei_width; self.xtfei_height = view.xtfei_height; } [self setupSubviews]; } - (void)setupSubviews { } - (void)willMoveToSuperview:(UIView *)newSuperview { [super willMoveToSuperview:newSuperview]; if (newSuperview && ![newSuperview isKindOfClass:[UIView class]]) return; if (newSuperview) { self.xtfei_width = newSuperview.xtfei_width; self.xtfei_height = newSuperview.xtfei_height; } } #pragma mark 实例化 + (instancetype)emptyActionViewWithImage:(NSString *)image title:(NSString *)title detail:(NSString *)detail btnTitle:(NSString *)btnTitle target:(id)target action:(SEL)action { TFEmptyBaseView *emptyView = [[self alloc] init]; [emptyView creatEmptyViewWithImage:image title:title detail:detail btnTitle:btnTitle target:target action:action]; return emptyView; } + (instancetype)emptyActionViewWithImage:(NSString *)image title:(NSString *)title detail:(NSString *)detail btnTitle:(NSString *)btnTitle btnClickBlock:(TFActionTapBlock)btnClickBlock { TFEmptyBaseView *emptyView = [[self alloc] init]; [emptyView creatEmptyViewWithImage:image title:title detail:detail btnTitle:btnTitle btnClickBlock:btnClickBlock]; return emptyView; } + (instancetype)emptyViewWithImage:(NSString *)image title:(NSString *)title detail:(NSString *)detail { TFEmptyBaseView *emptyView = [[self alloc] init]; [emptyView creatEmptyViewWithImage:image title:title detail:detail btnTitle:nil btnClickBlock:nil]; return emptyView; } + (instancetype)emptyViewWithCustomView:(UIView *)customView { TFEmptyBaseView *emptyView = [[self alloc] init]; [emptyView creatEmptyViewWithCustomView:customView]; return emptyView; } - (void)creatEmptyViewWithImage:(NSString *)image title:(NSString *)title detail:(NSString *)detail btnTitle:(NSString *)btnTitle target:(id)target action:(SEL)action { _image = image; _title = title; _detail = detail; _btnTitle = btnTitle; _actionBtnTarget = target; _actionBtnAction = action; if (!_contentView) { _contentView = [[UIView alloc] initWithFrame:CGRectZero]; [self addSubview:_contentView]; UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapGestureRecognizer:)]; [_contentView addGestureRecognizer:tap]; } } - (void)creatEmptyViewWithImage:(NSString *)image title:(NSString *)title detail:(NSString *)detail btnTitle:(NSString *)btnTitle btnClickBlock:(TFActionTapBlock)btnClickBlock { _image = image; _title = title; _detail = detail; _btnTitle = btnTitle; _btnClickBlock = btnClickBlock; if (!_contentView) { _contentView = [[UIView alloc] initWithFrame:CGRectZero]; [self addSubview:_contentView]; UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapGestureRecognizer:)]; [_contentView addGestureRecognizer:tap]; } } - (void)creatEmptyViewWithCustomView:(UIView *)customView { if (!_contentView) { _contentView = [[UIView alloc] initWithFrame:CGRectZero]; [self addSubview:_contentView]; } if (!_customView) { [_contentView addSubview:customView]; } _customView = customView; } #pragma mark Setter - (void)setImage:(NSString *)image { _image = image; [self layoutSubviews]; } - (void)setTitle:(NSString *)title { _title = title; [self layoutSubviews]; } - (void)setDetail:(NSString *)detail { _detail = detail; [self layoutSubviews]; } - (void)setBtnTitle:(NSString *)btnTitle { _btnTitle = btnTitle; [self layoutSubviews]; } - (void)tapGestureRecognizer:(UITapGestureRecognizer *)tap { if (_tapContentViewBlock) { _tapContentViewBlock(); } } @end