GHRefreshFooter.m 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. //
  2. // GHRefreshFooter.m
  3. // GameHelper
  4. //
  5. // Created by 青秀斌 on 16/12/29.
  6. // Copyright © 2016年 kylincc. All rights reserved.
  7. //
  8. #import "GHRefreshFooter.h"
  9. #import "UILabel+GHConfig.h"
  10. #import "GHThemeManager.h"
  11. #import "UIView+GHTheme.h"
  12. @interface GHRefreshFooter ()
  13. @property (strong, nonatomic) UILabel *stateLabel;
  14. @property (strong, nonatomic) UIActivityIndicatorView *loadingView;
  15. @property (strong, nonatomic) GHThemeManager *themeManager;
  16. @end
  17. @implementation GHRefreshFooter
  18. - (void)dealloc{
  19. [self unObserveThemeChange];
  20. }
  21. - (instancetype)init {
  22. self = [super init];
  23. self.textForIdle = @"上拉即可加载更多...";
  24. self.textForPulling = @"释放即可加载更多...";
  25. self.textForRefreshing = @"正在加载...";
  26. self.textForNoMoreData = @"没有更多了";
  27. self.themeManager = [[GHThemeManager alloc] init];
  28. self.backgroundColor = [UIColor clearColor];
  29. return self;
  30. }
  31. /**********************************************************************/
  32. #pragma mark - OverWrite
  33. /**********************************************************************/
  34. - (void)themeChangeAction{
  35. self.stateLabel.configText = @"T2";
  36. if (self.themeManager.themeType == ThemeType_Night) {
  37. self.loadingView.activityIndicatorViewStyle = UIActivityIndicatorViewStyleWhite;
  38. }else{
  39. self.loadingView.activityIndicatorViewStyle = UIActivityIndicatorViewStyleGray;
  40. }
  41. }
  42. /**********************************************************************/
  43. #pragma mark - Private
  44. /**********************************************************************/
  45. - (void)prepare {
  46. [super prepare];
  47. self.mj_h = 50;
  48. self.triggerAutomaticallyRefreshPercent = 0.0f;
  49. if (self.stateLabel == nil) {
  50. self.stateLabel = [[UILabel alloc] init];
  51. self.stateLabel.textAlignment = NSTextAlignmentCenter;
  52. self.stateLabel.font = [UIFont boldSystemFontOfSize:11];
  53. self.stateLabel.backgroundColor = [UIColor clearColor];
  54. [self addSubview:self.stateLabel];
  55. }
  56. if (self.loadingView == nil) {
  57. self.loadingView = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleGray];
  58. [self addSubview:self.loadingView];
  59. }
  60. [self themeChangeAction];
  61. [self observeThemeChange];
  62. }
  63. - (void)placeSubviews {
  64. [super placeSubviews];
  65. self.stateLabel.frame = self.bounds;
  66. self.loadingView.center = CGPointMake(self.mj_w * 0.5, self.mj_h * 0.5);
  67. }
  68. #pragma mark 监听控件的刷新状态
  69. - (void)setState:(MJRefreshState)state {
  70. MJRefreshCheckState;
  71. switch (state) {
  72. case MJRefreshStateIdle:{
  73. self.stateLabel.hidden = NO;
  74. self.stateLabel.text = self.textForIdle;
  75. [self.loadingView stopAnimating];
  76. }break;
  77. case MJRefreshStatePulling:{
  78. self.stateLabel.hidden = NO;
  79. self.stateLabel.text = self.textForPulling;
  80. [self.loadingView stopAnimating];
  81. }break;
  82. case MJRefreshStateRefreshing:{
  83. self.stateLabel.hidden = YES;
  84. self.stateLabel.text = self.textForRefreshing;
  85. [self.loadingView startAnimating];
  86. }break;
  87. case MJRefreshStateNoMoreData:{
  88. self.stateLabel.hidden = NO;
  89. self.stateLabel.text = self.textForNoMoreData;
  90. [self.loadingView stopAnimating];
  91. }break;
  92. default:break;
  93. }
  94. self.stateLabel.textColor = RGB(194, 194, 194);
  95. }
  96. @end