CGXRefreshHeader.m 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. //
  2. // CGXMJRefreshHeader.m
  3. // CGXVerticalMenuView-OC
  4. //
  5. // Created by CGX on 2018/05/01.
  6. // Copyright © 2019 CGX. All rights reserved.
  7. //
  8. #import "CGXRefreshHeader.h"
  9. @interface CGXRefreshHeader()
  10. @property (weak, nonatomic) UILabel *label;
  11. @end
  12. @implementation CGXRefreshHeader
  13. #pragma mark - 重写方法
  14. #pragma mark 在这里做一些初始化配置(比如添加子控件)
  15. - (void)prepare
  16. {
  17. [super prepare];
  18. // 设置控件的高度
  19. self.mj_h = 60;
  20. // 添加label
  21. UILabel *label = [[UILabel alloc] init];
  22. label.textColor = RQ_MAIN_COLOR;
  23. label.font = [UIFont boldSystemFontOfSize:16];
  24. label.textAlignment = NSTextAlignmentCenter;
  25. label.numberOfLines = 0;
  26. label.adjustsFontSizeToFitWidth = YES;
  27. [self addSubview:label];
  28. self.label = label;
  29. }
  30. - (void)setTitle:(NSString *)title
  31. {
  32. _title = title;
  33. self.label.text = self.title;
  34. }
  35. #pragma mark 在这里设置子控件的位置和尺寸
  36. - (void)placeSubviews
  37. {
  38. [super placeSubviews];
  39. self.label.frame = self.bounds;
  40. }
  41. #pragma mark 监听scrollView的contentOffset改变
  42. - (void)scrollViewContentOffsetDidChange:(NSDictionary *)change
  43. {
  44. [super scrollViewContentOffsetDidChange:change];
  45. }
  46. #pragma mark 监听scrollView的contentSize改变
  47. - (void)scrollViewContentSizeDidChange:(NSDictionary *)change
  48. {
  49. [super scrollViewContentSizeDidChange:change];
  50. }
  51. #pragma mark 监听scrollView的拖拽状态改变
  52. - (void)scrollViewPanStateDidChange:(NSDictionary *)change
  53. {
  54. [super scrollViewPanStateDidChange:change];
  55. }
  56. #pragma mark 监听控件的刷新状态
  57. - (void)setState:(MJRefreshState)state
  58. {
  59. MJRefreshCheckState;
  60. switch (state) {
  61. case MJRefreshStateIdle:
  62. self.label.text = @"下拉继续浏览";
  63. break;
  64. case MJRefreshStatePulling:
  65. self.label.text = @"下拉继续浏览";
  66. break;
  67. case MJRefreshStateRefreshing:
  68. self.label.text = @"下拉继续浏览";
  69. break;
  70. default:
  71. break;
  72. }
  73. self.label.text = self.title;
  74. }
  75. #pragma mark 监听拖拽比例(控件被拖出来的比例)
  76. - (void)setPullingPercent:(CGFloat)pullingPercent
  77. {
  78. [super setPullingPercent:pullingPercent];
  79. // 1.0 0.5 0.0
  80. // 0.5 0.0 0.5
  81. // CGFloat red = 1.0 - pullingPercent * 0.5;
  82. // CGFloat green = 0.5 - 0.5 * pullingPercent;
  83. // CGFloat blue = 0.5 * pullingPercent;
  84. // self.label.textColor = [UIColor colorWithRed:red green:green blue:blue alpha:1.0];
  85. }
  86. /*
  87. // Only override drawRect: if you perform custom drawing.
  88. // An empty implementation adversely affects performance during animation.
  89. - (void)drawRect:(CGRect)rect {
  90. // Drawing code
  91. }
  92. */
  93. @end