RAEmptyView.m 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. //
  2. // RAEmptyView.m
  3. // Apex And Drivers
  4. //
  5. // Created by Jack on 2018/9/5.
  6. // Copyright © 2018年 USAI. All rights reserved.
  7. //
  8. #import "RAEmptyView.h"
  9. @interface RAEmptyView ()
  10. @property (nonatomic,copy) void(^tapEmptyBlk)(id sender);
  11. @property (nonatomic,strong) UILabel *tipLabel;
  12. @end
  13. @implementation RAEmptyView
  14. + (instancetype)emptyViewWithTapBlk:(void(^)(id sender))tapEmptyBlk {
  15. RAEmptyView *emptyView = [RAEmptyView new];
  16. emptyView.frame = CGRectMake(0, 0, 200, 80);
  17. emptyView.tapEmptyBlk = tapEmptyBlk;
  18. return emptyView;
  19. }
  20. - (instancetype)init {
  21. if (self = [super init]) {
  22. self.layer.borderColor = [UIColor grayColor].CGColor;
  23. self.layer.borderWidth = 0.5f;
  24. self.layer.cornerRadius = 5.0f;
  25. self.layer.masksToBounds = YES;
  26. [self addSubview:self.tipLabel];
  27. UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapEmpty:)];
  28. [self addGestureRecognizer:tap];
  29. }
  30. return self;
  31. }
  32. - (void)layoutSubviews {
  33. [super layoutSubviews];
  34. self.tipLabel.frame = self.bounds;
  35. }
  36. - (UILabel *)tipLabel {
  37. if (!_tipLabel) {
  38. _tipLabel = [[UILabel alloc] init];
  39. NSString *tips = NSLocalizedString(@"empty_tips", nil);
  40. if ([tips isEqualToString:@"empty_tips"]) {
  41. tips = @"Reload";
  42. }
  43. _tipLabel.text = tips;
  44. _tipLabel.numberOfLines = 0;
  45. _tipLabel.textAlignment = NSTextAlignmentCenter;
  46. }
  47. return _tipLabel;
  48. }
  49. - (void)tapEmpty:(UITapGestureRecognizer *)tap {
  50. if (self.tapEmptyBlk) {
  51. self.tapEmptyBlk(tap);
  52. }
  53. }
  54. @end