UIScrollView+Refresh.m 3.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. //
  2. // UIScrollView+Refresh.m
  3. // homy
  4. //
  5. // Created by 翟玉磊 on 2018/11/9.
  6. // Copyright © 2018 翟玉磊. All rights reserved.
  7. //
  8. #import "UIScrollView+Refresh.h"
  9. #import "BaseRefreshHeader.h"
  10. #import "BaseRefreshFooter.h"
  11. #import "BaseRefreshAutoNormalFooter.h"
  12. #import "BaseLottieRefreshHeader.h"
  13. @implementation UIScrollView (Refresh)
  14. /// 添加下拉刷新控件
  15. - (MJRefreshHeader *)addHeaderRefresh:(void(^)(MJRefreshHeader *header))refreshingBlock {
  16. __weak typeof(&*self) weakSelf = self;
  17. BaseLottieRefreshHeader *mj_header = [BaseLottieRefreshHeader headerWithRefreshingBlock:^{
  18. __strong typeof(&*weakSelf) strongSelf = weakSelf;
  19. !refreshingBlock?:refreshingBlock((MJRefreshNormalHeader *)strongSelf.mj_header);
  20. }];
  21. // 设置自动切换透明度(在导航栏下面自动隐藏)
  22. mj_header.automaticallyChangeAlpha = YES;
  23. // Configure normal mj_header
  24. self.mj_header = mj_header;
  25. return mj_header;
  26. }
  27. /// 添加上拉加载控件
  28. - (MJRefreshFooter *)addFooterRefresh:(void(^)(MJRefreshFooter *footer))refreshingBlock {
  29. __weak typeof(&*self) weakSelf = self;
  30. BaseRefreshFooter *mj_footer = [BaseRefreshFooter footerWithRefreshingBlock:^{
  31. __strong typeof(&*weakSelf) strongSelf = weakSelf;
  32. !refreshingBlock?:refreshingBlock((MJRefreshAutoNormalFooter *)strongSelf.mj_footer);
  33. }];
  34. self.mj_footer = mj_footer;
  35. return mj_footer;
  36. }
  37. /// 添加下拉刷新控件
  38. - (MJRefreshHeader *)addImageHeaderRefresh:(void(^)(MJRefreshHeader *header))refreshingBlock {
  39. __weak typeof(&*self) weakSelf = self;
  40. BaseRefreshHeader *mj_header = [BaseRefreshHeader headerWithRefreshingBlock:^{
  41. __strong typeof(&*weakSelf) strongSelf = weakSelf;
  42. !refreshingBlock?:refreshingBlock((MJRefreshNormalHeader *)strongSelf.mj_header);
  43. }];
  44. // 设置自动切换透明度(在导航栏下面自动隐藏)
  45. mj_header.automaticallyChangeAlpha = YES;
  46. // Configure normal mj_header
  47. self.mj_header = mj_header;
  48. return mj_header;
  49. }
  50. /// 添加上拉加载控件
  51. - (MJRefreshFooter *)addImageFooterRefresh:(void(^)(MJRefreshFooter *footer))refreshingBlock {
  52. __weak typeof(&*self) weakSelf = self;
  53. BaseRefreshFooter *mj_footer = [BaseRefreshFooter footerWithRefreshingBlock:^{
  54. __strong typeof(&*weakSelf) strongSelf = weakSelf;
  55. !refreshingBlock?:refreshingBlock((MJRefreshAutoNormalFooter *)strongSelf.mj_footer);
  56. }];
  57. self.mj_footer = mj_footer;
  58. return mj_footer;
  59. }
  60. /// 添加下拉刷新控件
  61. - (MJRefreshNormalHeader *)native_addHeaderRefresh:(void(^)(MJRefreshNormalHeader *header))refreshingBlock {
  62. __weak __typeof(&*self) weakSelf = self;
  63. MJRefreshNormalHeader *mj_header = [MJRefreshNormalHeader headerWithRefreshingBlock:^{
  64. __weak __typeof(&*weakSelf) strongSelf = weakSelf;
  65. !refreshingBlock?:refreshingBlock((MJRefreshNormalHeader *)strongSelf.mj_header);
  66. }];
  67. mj_header.lastUpdatedTimeLabel.hidden = YES;
  68. // Configure normal mj_header
  69. self.mj_header = mj_header;
  70. return mj_header;
  71. }
  72. /// 添加上拉加载控件
  73. - (BaseRefreshAutoNormalFooter *)native_addFooterRefresh:(void(^)(MJRefreshAutoNormalFooter *footer))refreshingBlock {
  74. __weak __typeof(&*self) weakSelf = self;
  75. BaseRefreshAutoNormalFooter *mj_footer = [BaseRefreshAutoNormalFooter footerWithRefreshingBlock:^{
  76. __weak __typeof(&*weakSelf) strongSelf = weakSelf;
  77. !refreshingBlock?:refreshingBlock((BaseRefreshAutoNormalFooter *)strongSelf.mj_footer);
  78. }];
  79. // Configure normal mj_footer
  80. [mj_footer setTitle:@"~ 持续更新中 ~" forState:MJRefreshStateNoMoreData];
  81. [mj_footer setTitleColor:Color(204, 204, 204) forState:MJRefreshStateNoMoreData];
  82. self.mj_footer = mj_footer;
  83. return mj_footer;
  84. }
  85. @end