UIScrollView+MJExtension.m 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. // 代码地址: https://github.com/CoderMJLee/MJRefresh
  2. // 代码地址: http://code4app.com/ios/%E5%BF%AB%E9%80%9F%E9%9B%86%E6%88%90%E4%B8%8B%E6%8B%89%E4%B8%8A%E6%8B%89%E5%88%B7%E6%96%B0/52326ce26803fabc46000000
  3. // UIScrollView+Extension.m
  4. // MJRefreshExample
  5. //
  6. // Created by MJ Lee on 14-5-28.
  7. // Copyright (c) 2014年 小码哥. All rights reserved.
  8. //
  9. #import "UIScrollView+MJExtension.h"
  10. #import <objc/runtime.h>
  11. @implementation UIScrollView (MJExtension)
  12. - (UIEdgeInsets)mj_inset
  13. {
  14. #ifdef __IPHONE_11_0
  15. if(@available(iOS 11.0, *)){
  16. return self.adjustedContentInset;
  17. }
  18. #endif
  19. return self.contentInset;
  20. }
  21. - (void)setMj_insetT:(CGFloat)mj_insetT
  22. {
  23. UIEdgeInsets inset = self.contentInset;
  24. inset.top = mj_insetT;
  25. #ifdef __IPHONE_11_0
  26. if(@available(iOS 11.0, *)){
  27. inset.top -= (self.adjustedContentInset.top - self.contentInset.top);
  28. }
  29. #endif
  30. self.contentInset = inset;
  31. }
  32. - (CGFloat)mj_insetT
  33. {
  34. return self.mj_inset.top;
  35. }
  36. - (void)setMj_insetB:(CGFloat)mj_insetB
  37. {
  38. UIEdgeInsets inset = self.contentInset;
  39. inset.bottom = mj_insetB;
  40. #ifdef __IPHONE_11_0
  41. if(@available(iOS 11.0, *)){
  42. inset.bottom -= (self.adjustedContentInset.bottom - self.contentInset.bottom);
  43. }
  44. #endif
  45. self.contentInset = inset;
  46. }
  47. - (CGFloat)mj_insetB
  48. {
  49. return self.mj_inset.bottom;
  50. }
  51. - (void)setMj_insetL:(CGFloat)mj_insetL
  52. {
  53. UIEdgeInsets inset = self.contentInset;
  54. inset.left = mj_insetL;
  55. self.contentInset = inset;
  56. }
  57. - (CGFloat)mj_insetL
  58. {
  59. return self.contentInset.left;
  60. }
  61. - (void)setMj_insetR:(CGFloat)mj_insetR
  62. {
  63. UIEdgeInsets inset = self.contentInset;
  64. inset.right = mj_insetR;
  65. self.contentInset = inset;
  66. }
  67. - (CGFloat)mj_insetR
  68. {
  69. return self.contentInset.right;
  70. }
  71. - (void)setMj_offsetX:(CGFloat)mj_offsetX
  72. {
  73. CGPoint offset = self.contentOffset;
  74. offset.x = mj_offsetX;
  75. self.contentOffset = offset;
  76. }
  77. - (CGFloat)mj_offsetX
  78. {
  79. return self.contentOffset.x;
  80. }
  81. - (void)setMj_offsetY:(CGFloat)mj_offsetY
  82. {
  83. CGPoint offset = self.contentOffset;
  84. offset.y = mj_offsetY;
  85. self.contentOffset = offset;
  86. }
  87. - (CGFloat)mj_offsetY
  88. {
  89. return self.contentOffset.y;
  90. }
  91. - (void)setMj_contentW:(CGFloat)mj_contentW
  92. {
  93. CGSize size = self.contentSize;
  94. size.width = mj_contentW;
  95. self.contentSize = size;
  96. }
  97. - (CGFloat)mj_contentW
  98. {
  99. return self.contentSize.width;
  100. }
  101. - (void)setMj_contentH:(CGFloat)mj_contentH
  102. {
  103. CGSize size = self.contentSize;
  104. size.height = mj_contentH;
  105. self.contentSize = size;
  106. }
  107. - (CGFloat)mj_contentH
  108. {
  109. return self.contentSize.height;
  110. }
  111. @end