MJRefreshBackStateFooter.m 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  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 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 setTitle:MJRefreshBackFooterIdleText forState:MJRefreshStateIdle];
  49. [self setTitle:MJRefreshBackFooterPullingText forState:MJRefreshStatePulling];
  50. [self setTitle:MJRefreshBackFooterRefreshingText forState:MJRefreshStateRefreshing];
  51. [self setTitle:MJRefreshBackFooterNoMoreDataText forState:MJRefreshStateNoMoreData];
  52. }
  53. - (void)placeSubviews
  54. {
  55. [super placeSubviews];
  56. if (self.stateLabel.constraints.count) return;
  57. // 状态标签
  58. self.stateLabel.frame = self.bounds;
  59. }
  60. - (void)setState:(MJRefreshState)state
  61. {
  62. MJRefreshCheckState
  63. // 设置状态文字
  64. self.stateLabel.text = self.stateTitles[@(state)];
  65. }
  66. @end