| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283 |
- //
- // RAEmptyView.m
- // Apex And Drivers
- //
- // Created by Jack on 2018/9/5.
- // Copyright © 2018年 USAI. All rights reserved.
- //
- #import "RAEmptyView.h"
- @interface RAEmptyView ()
- @property (nonatomic,copy) void(^tapEmptyBlk)(id sender);
- @property (nonatomic,strong) UILabel *tipLabel;
- @end
- @implementation RAEmptyView
- + (instancetype)emptyViewWithTapBlk:(void(^)(id sender))tapEmptyBlk {
- RAEmptyView *emptyView = [RAEmptyView new];
- emptyView.frame = CGRectMake(0, 0, 200, 80);
- emptyView.tapEmptyBlk = tapEmptyBlk;
-
- return emptyView;
- }
- + (instancetype)emptyViewWithTitle:(NSString *)title clickHandler:(void(^)(id sender))handler {
-
- RAEmptyView *emptyView = [RAEmptyView new];
- emptyView.tapEmptyBlk = handler;
-
- emptyView.tipLabel.text = title;
-
- [emptyView.tipLabel sizeToFit];
- CGSize size = emptyView.bounds.size;
- emptyView.frame = CGRectMake(0, 0, size.width + 10, size.height + 10);
-
- return emptyView;
- }
- - (instancetype)init {
-
- if (self = [super init]) {
- self.layer.borderColor = [UIColor grayColor].CGColor;
- self.layer.borderWidth = 0.5f;
- self.layer.cornerRadius = 5.0f;
- self.layer.masksToBounds = YES;
- [self addSubview:self.tipLabel];
-
- UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapEmpty:)];
- [self addGestureRecognizer:tap];
- }
- return self;
- }
- - (void)layoutSubviews {
- [super layoutSubviews];
-
- self.tipLabel.frame = self.bounds;
- }
- - (UILabel *)tipLabel {
- if (!_tipLabel) {
- _tipLabel = [[UILabel alloc] init];
- NSString *tips = NSLocalizedString(@"empty_tips", nil);
- if ([tips isEqualToString:@"empty_tips"]) {
- tips = @"Reload";
- }
- _tipLabel.text = tips;
- _tipLabel.numberOfLines = 0;
- _tipLabel.textAlignment = NSTextAlignmentCenter;
- }
- return _tipLabel;
- }
- - (void)tapEmpty:(UITapGestureRecognizer *)tap {
- if (self.tapEmptyBlk) {
- self.tapEmptyBlk(tap);
- }
- }
- @end
|