MJDIYBackFooter.m 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. //
  2. // MJDIYBackFooter.m
  3. // MJRefreshExample
  4. //
  5. // Created by MJ Lee on 15/6/13.
  6. // Copyright © 2015年 小码哥. All rights reserved.
  7. //
  8. #import "MJDIYBackFooter.h"
  9. @interface MJDIYBackFooter()
  10. @property (weak, nonatomic) UILabel *label;
  11. @property (weak, nonatomic) UISwitch *s;
  12. @property (weak, nonatomic) UIImageView *logo;
  13. @property (weak, nonatomic) UIActivityIndicatorView *loading;
  14. @end
  15. @implementation MJDIYBackFooter
  16. #pragma mark - 重写方法
  17. #pragma mark 在这里做一些初始化配置(比如添加子控件)
  18. - (void)prepare
  19. {
  20. [super prepare];
  21. // 设置控件的高度
  22. self.mj_h = 50;
  23. // 添加label
  24. UILabel *label = [[UILabel alloc] init];
  25. label.textColor = [UIColor colorWithRed:1.0 green:0.5 blue:0.0 alpha:1.0];
  26. label.font = [UIFont boldSystemFontOfSize:16];
  27. label.textAlignment = NSTextAlignmentCenter;
  28. [self addSubview:label];
  29. self.label = label;
  30. // 打酱油的开关
  31. UISwitch *s = [[UISwitch alloc] init];
  32. [self addSubview:s];
  33. self.s = s;
  34. // logo
  35. UIImageView *logo = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"Logo"]];
  36. logo.contentMode = UIViewContentModeScaleAspectFit;
  37. [self addSubview:logo];
  38. self.logo = logo;
  39. // loading
  40. UIActivityIndicatorView *loading = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleGray];
  41. [self addSubview:loading];
  42. self.loading = loading;
  43. }
  44. #pragma mark 在这里设置子控件的位置和尺寸
  45. - (void)placeSubviews
  46. {
  47. [super placeSubviews];
  48. self.label.frame = self.bounds;
  49. self.logo.bounds = CGRectMake(0, 0, self.bounds.size.width, 100);
  50. self.logo.center = CGPointMake(self.mj_w * 0.5, self.mj_h + self.logo.mj_h * 0.5);
  51. self.loading.center = CGPointMake(self.mj_w - 30, self.mj_h * 0.5);
  52. }
  53. #pragma mark 监听scrollView的contentOffset改变
  54. - (void)scrollViewContentOffsetDidChange:(NSDictionary *)change
  55. {
  56. [super scrollViewContentOffsetDidChange:change];
  57. }
  58. #pragma mark 监听scrollView的contentSize改变
  59. - (void)scrollViewContentSizeDidChange:(NSDictionary *)change
  60. {
  61. [super scrollViewContentSizeDidChange:change];
  62. }
  63. #pragma mark 监听scrollView的拖拽状态改变
  64. - (void)scrollViewPanStateDidChange:(NSDictionary *)change
  65. {
  66. [super scrollViewPanStateDidChange:change];
  67. }
  68. #pragma mark 监听控件的刷新状态
  69. - (void)setState:(MJRefreshState)state
  70. {
  71. MJRefreshCheckState;
  72. switch (state) {
  73. case MJRefreshStateIdle:
  74. [self.loading stopAnimating];
  75. [self.s setOn:NO animated:YES];
  76. self.label.text = @"赶紧上拉吖(开关是打酱油滴)";
  77. break;
  78. case MJRefreshStatePulling:
  79. [self.loading stopAnimating];
  80. [self.s setOn:YES animated:YES];
  81. self.label.text = @"赶紧放开我吧(开关是打酱油滴)";
  82. break;
  83. case MJRefreshStateRefreshing:
  84. [self.loading startAnimating];
  85. [self.s setOn:YES animated:YES];
  86. self.label.text = @"加载数据中(开关是打酱油滴)";
  87. break;
  88. case MJRefreshStateNoMoreData:
  89. [self.loading stopAnimating];
  90. self.label.text = @"木有数据了(开关是打酱油滴)";
  91. [self.s setOn:NO animated:YES];
  92. default:
  93. break;
  94. }
  95. }
  96. #pragma mark 监听拖拽比例(控件被拖出来的比例)
  97. - (void)setPullingPercent:(CGFloat)pullingPercent
  98. {
  99. [super setPullingPercent:pullingPercent];
  100. // 1.0 0.5 0.0
  101. // 0.5 0.0 0.5
  102. CGFloat red = 1.0 - pullingPercent * 0.5;
  103. CGFloat green = 0.5 - 0.5 * pullingPercent;
  104. CGFloat blue = 0.5 * pullingPercent;
  105. self.label.textColor = [UIColor colorWithRed:red green:green blue:blue alpha:1.0];
  106. }
  107. @end