UIScrollView+JLRefresh.m 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. //
  2. // UIScrollView+JLRefresh.m
  3. // JLRefreshDemo
  4. //
  5. // Created by Jack on 2017/3/3.
  6. // Copyright © 2017年 mini1. All rights reserved.
  7. //
  8. #import "UIScrollView+JLRefresh.h"
  9. #import "JLRefreshBasis.h"
  10. #import <objc/runtime.h>
  11. @implementation UIScrollView (JLRefresh)
  12. static const char JLHeaderKey = '\a';
  13. - (void)setJl_header:(JLRefreshBasis *)jl_header {
  14. if (jl_header) {
  15. [self.jl_header removeFromSuperview];
  16. [self insertSubview:jl_header atIndex:0];
  17. [self willChangeValueForKey:@"jl_header"];
  18. objc_setAssociatedObject(self, &JLHeaderKey, jl_header, OBJC_ASSOCIATION_ASSIGN);
  19. [self didChangeValueForKey:@"jl_header"];
  20. }
  21. }
  22. - (JLRefreshBasis *)jl_header {
  23. return objc_getAssociatedObject(self, &JLHeaderKey);
  24. }
  25. static const char JLFooterKey = '\b';
  26. - (void)setJl_footer:(JLRefreshBasis *)jl_footer {
  27. if (jl_footer) {
  28. [self.jl_footer removeFromSuperview];
  29. [self insertSubview:jl_footer atIndex:0];
  30. [self willChangeValueForKey:@"jl_footer"];
  31. objc_setAssociatedObject(self, &JLFooterKey, jl_footer, OBJC_ASSOCIATION_ASSIGN);
  32. [self didChangeValueForKey:@"jl_footer"];
  33. }
  34. }
  35. - (JLRefreshBasis *)jl_footer {
  36. return objc_getAssociatedObject(self, &JLFooterKey);
  37. }
  38. - (void)setJl_offsetY:(CGFloat)jl_offsetY {
  39. CGPoint contentOff = self.contentOffset;
  40. contentOff.y = jl_offsetY;
  41. self.contentOffset = contentOff;
  42. }
  43. - (CGFloat)jl_offsetY {
  44. return self.contentOffset.y;
  45. }
  46. - (void)setJl_insetTop:(CGFloat)jl_insetTop {
  47. UIEdgeInsets inset = self.contentInset;
  48. inset.top = jl_insetTop;
  49. self.contentInset = inset;
  50. }
  51. - (CGFloat)jl_insetTop {
  52. return self.contentInset.top;
  53. }
  54. - (void)setJl_insetBottom:(CGFloat)jl_insetBottom {
  55. UIEdgeInsets inset = self.contentInset;
  56. inset.bottom = jl_insetBottom;
  57. self.contentInset = inset;
  58. }
  59. - (CGFloat)jl_insetBottom {
  60. return self.contentInset.bottom;
  61. }
  62. - (void)setJl_ContentHeight:(CGFloat)jl_ContentHeight {
  63. CGSize contentSize = self.contentSize;
  64. contentSize.height = jl_ContentHeight;
  65. self.contentSize = contentSize;
  66. }
  67. - (CGFloat)jl_ContentHeight {
  68. return self.contentSize.height;
  69. }
  70. @end