RAEmptyView.m 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  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. _tipLabel.text = @"There is no data\nPlease click to reload";
  40. _tipLabel.numberOfLines = 0;
  41. _tipLabel.textAlignment = NSTextAlignmentCenter;
  42. }
  43. return _tipLabel;
  44. }
  45. - (void)tapEmpty:(UITapGestureRecognizer *)tap {
  46. if (self.tapEmptyBlk) {
  47. self.tapEmptyBlk(tap);
  48. }
  49. }
  50. @end