RAEmptyView.m 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  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)emptyViewWithTitle:(NSString *)title clickHandler:(void(^)(id sender))handler {
  21. RAEmptyView *emptyView = [RAEmptyView new];
  22. emptyView.tapEmptyBlk = handler;
  23. emptyView.tipLabel.text = title;
  24. [emptyView.tipLabel sizeToFit];
  25. CGSize size = emptyView.bounds.size;
  26. emptyView.frame = CGRectMake(0, 0, size.width + 10, size.height + 10);
  27. return emptyView;
  28. }
  29. - (instancetype)init {
  30. if (self = [super init]) {
  31. self.layer.borderColor = [UIColor grayColor].CGColor;
  32. self.layer.borderWidth = 0.5f;
  33. self.layer.cornerRadius = 5.0f;
  34. self.layer.masksToBounds = YES;
  35. [self addSubview:self.tipLabel];
  36. UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapEmpty:)];
  37. [self addGestureRecognizer:tap];
  38. }
  39. return self;
  40. }
  41. - (void)layoutSubviews {
  42. [super layoutSubviews];
  43. self.tipLabel.frame = self.bounds;
  44. }
  45. - (UILabel *)tipLabel {
  46. if (!_tipLabel) {
  47. _tipLabel = [[UILabel alloc] init];
  48. NSString *tips = NSLocalizedString(@"empty_tips", nil);
  49. if ([tips isEqualToString:@"empty_tips"]) {
  50. tips = @"Reload";
  51. }
  52. _tipLabel.text = tips;
  53. _tipLabel.numberOfLines = 0;
  54. _tipLabel.textAlignment = NSTextAlignmentCenter;
  55. }
  56. return _tipLabel;
  57. }
  58. - (void)tapEmpty:(UITapGestureRecognizer *)tap {
  59. if (self.tapEmptyBlk) {
  60. self.tapEmptyBlk(tap);
  61. }
  62. }
  63. @end