MJRefreshAutoNormalFooter.m 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. //
  2. // MJRefreshAutoNormalFooter.m
  3. // MJRefreshExample
  4. //
  5. // Created by MJ Lee on 15/4/24.
  6. // Copyright (c) 2015年 小码哥. All rights reserved.
  7. //
  8. #import "MJRefreshAutoNormalFooter.h"
  9. @interface MJRefreshAutoNormalFooter()
  10. @property (weak, nonatomic) UIActivityIndicatorView *loadingView;
  11. @end
  12. @implementation MJRefreshAutoNormalFooter
  13. #pragma mark - 懒加载子控件
  14. - (UIActivityIndicatorView *)loadingView
  15. {
  16. if (!_loadingView) {
  17. UIActivityIndicatorView *loadingView = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:self.activityIndicatorViewStyle];
  18. loadingView.hidesWhenStopped = YES;
  19. [self addSubview:_loadingView = loadingView];
  20. }
  21. return _loadingView;
  22. }
  23. - (void)setActivityIndicatorViewStyle:(UIActivityIndicatorViewStyle)activityIndicatorViewStyle
  24. {
  25. _activityIndicatorViewStyle = activityIndicatorViewStyle;
  26. self.loadingView = nil;
  27. [self setNeedsLayout];
  28. }
  29. #pragma mark - 重写父类的方法
  30. - (void)prepare
  31. {
  32. [super prepare];
  33. self.activityIndicatorViewStyle = UIActivityIndicatorViewStyleGray;
  34. }
  35. - (void)placeSubviews
  36. {
  37. [super placeSubviews];
  38. if (self.loadingView.constraints.count) return;
  39. // 圈圈
  40. CGFloat loadingCenterX = self.mj_w * 0.5;
  41. if (!self.isRefreshingTitleHidden) {
  42. loadingCenterX -= self.stateLabel.mj_textWith * 0.5 + self.labelLeftInset;
  43. }
  44. CGFloat loadingCenterY = self.mj_h * 0.5;
  45. self.loadingView.center = CGPointMake(loadingCenterX, loadingCenterY);
  46. }
  47. - (void)setState:(MJRefreshState)state
  48. {
  49. MJRefreshCheckState
  50. // 根据状态做事情
  51. if (state == MJRefreshStateNoMoreData || state == MJRefreshStateIdle) {
  52. [self.loadingView stopAnimating];
  53. } else if (state == MJRefreshStateRefreshing) {
  54. [self.loadingView startAnimating];
  55. }
  56. }
  57. @end