MJRefreshBackStateFooter.m 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. //
  2. // MJRefreshBackStateFooter.m
  3. // MJRefreshExample
  4. //
  5. // Created by MJ Lee on 15/6/13.
  6. // Copyright © 2015年 小码哥. All rights reserved.
  7. //
  8. #import "MJRefreshBackStateFooter.h"
  9. @interface MJRefreshBackStateFooter()
  10. {
  11. /** 显示刷新状态的label */
  12. __unsafe_unretained UILabel *_stateLabel;
  13. }
  14. /** 所有状态对应的文字 */
  15. @property (strong, nonatomic) NSMutableDictionary *stateTitles;
  16. @end
  17. @implementation MJRefreshBackStateFooter
  18. #pragma mark - 懒加载
  19. - (NSMutableDictionary *)stateTitles
  20. {
  21. if (!_stateTitles) {
  22. self.stateTitles = [NSMutableDictionary dictionary];
  23. }
  24. return _stateTitles;
  25. }
  26. - (UILabel *)stateLabel
  27. {
  28. if (!_stateLabel) {
  29. [self addSubview:_stateLabel = [UILabel mj_label]];
  30. }
  31. return _stateLabel;
  32. }
  33. #pragma mark - 公共方法
  34. - (void)setTitle:(NSString *)title forState:(MJRefreshState)state
  35. {
  36. if (title == nil) return;
  37. self.stateTitles[@(state)] = title;
  38. self.stateLabel.text = self.stateTitles[@(self.state)];
  39. }
  40. - (NSString *)titleForState:(MJRefreshState)state {
  41. return self.stateTitles[@(state)];
  42. }
  43. #pragma mark - 重写父类的方法
  44. - (void)prepare
  45. {
  46. [super prepare];
  47. // 初始化间距
  48. self.labelLeftInset = MJRefreshLabelLeftInset;
  49. // 初始化文字
  50. [self setTitle:[NSBundle mj_localizedStringForKey:MJRefreshBackFooterIdleText] forState:MJRefreshStateIdle];
  51. [self setTitle:[NSBundle mj_localizedStringForKey:MJRefreshBackFooterPullingText] forState:MJRefreshStatePulling];
  52. [self setTitle:[NSBundle mj_localizedStringForKey:MJRefreshBackFooterRefreshingText] forState:MJRefreshStateRefreshing];
  53. [self setTitle:[NSBundle mj_localizedStringForKey:MJRefreshBackFooterNoMoreDataText] forState:MJRefreshStateNoMoreData];
  54. }
  55. - (void)placeSubviews
  56. {
  57. [super placeSubviews];
  58. if (self.stateLabel.constraints.count) return;
  59. // 状态标签
  60. self.stateLabel.frame = self.bounds;
  61. }
  62. - (void)setState:(MJRefreshState)state
  63. {
  64. MJRefreshCheckState
  65. // 设置状态文字
  66. self.stateLabel.text = self.stateTitles[@(state)];
  67. }
  68. @end