UIScrollView+MJExtension.m 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  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. #pragma clang diagnostic push
  12. #pragma clang diagnostic ignored "-Wunguarded-availability-new"
  13. @implementation UIScrollView (MJExtension)
  14. static BOOL gt_ios_11_;
  15. + (void)load
  16. {
  17. // 缓存判断值
  18. gt_ios_11_ = [[[UIDevice currentDevice] systemVersion] compare:@"11.0" options:NSNumericSearch] != NSOrderedAscending;
  19. }
  20. - (UIEdgeInsets)mj_inset
  21. {
  22. #ifdef __IPHONE_11_0
  23. if (gt_ios_11_) {
  24. return self.adjustedContentInset;
  25. }
  26. #endif
  27. return self.contentInset;
  28. }
  29. - (void)setMj_insetT:(CGFloat)mj_insetT
  30. {
  31. UIEdgeInsets inset = self.contentInset;
  32. inset.top = mj_insetT;
  33. #ifdef __IPHONE_11_0
  34. if (gt_ios_11_) {
  35. inset.top -= (self.adjustedContentInset.top - self.contentInset.top);
  36. }
  37. #endif
  38. self.contentInset = inset;
  39. }
  40. - (CGFloat)mj_insetT
  41. {
  42. return self.mj_inset.top;
  43. }
  44. - (void)setMj_insetB:(CGFloat)mj_insetB
  45. {
  46. UIEdgeInsets inset = self.contentInset;
  47. inset.bottom = mj_insetB;
  48. #ifdef __IPHONE_11_0
  49. if (gt_ios_11_) {
  50. inset.bottom -= (self.adjustedContentInset.bottom - self.contentInset.bottom);
  51. }
  52. #endif
  53. self.contentInset = inset;
  54. }
  55. - (CGFloat)mj_insetB
  56. {
  57. return self.mj_inset.bottom;
  58. }
  59. - (void)setMj_insetL:(CGFloat)mj_insetL
  60. {
  61. UIEdgeInsets inset = self.contentInset;
  62. inset.left = mj_insetL;
  63. #ifdef __IPHONE_11_0
  64. if (gt_ios_11_) {
  65. inset.left -= (self.adjustedContentInset.left - self.contentInset.left);
  66. }
  67. #endif
  68. self.contentInset = inset;
  69. }
  70. - (CGFloat)mj_insetL
  71. {
  72. return self.mj_inset.left;
  73. }
  74. - (void)setMj_insetR:(CGFloat)mj_insetR
  75. {
  76. UIEdgeInsets inset = self.contentInset;
  77. inset.right = mj_insetR;
  78. #ifdef __IPHONE_11_0
  79. if (gt_ios_11_) {
  80. inset.right -= (self.adjustedContentInset.right - self.contentInset.right);
  81. }
  82. #endif
  83. self.contentInset = inset;
  84. }
  85. - (CGFloat)mj_insetR
  86. {
  87. return self.mj_inset.right;
  88. }
  89. - (void)setMj_offsetX:(CGFloat)mj_offsetX
  90. {
  91. CGPoint offset = self.contentOffset;
  92. offset.x = mj_offsetX;
  93. self.contentOffset = offset;
  94. }
  95. - (CGFloat)mj_offsetX
  96. {
  97. return self.contentOffset.x;
  98. }
  99. - (void)setMj_offsetY:(CGFloat)mj_offsetY
  100. {
  101. CGPoint offset = self.contentOffset;
  102. offset.y = mj_offsetY;
  103. self.contentOffset = offset;
  104. }
  105. - (CGFloat)mj_offsetY
  106. {
  107. return self.contentOffset.y;
  108. }
  109. - (void)setMj_contentW:(CGFloat)mj_contentW
  110. {
  111. CGSize size = self.contentSize;
  112. size.width = mj_contentW;
  113. self.contentSize = size;
  114. }
  115. - (CGFloat)mj_contentW
  116. {
  117. return self.contentSize.width;
  118. }
  119. - (void)setMj_contentH:(CGFloat)mj_contentH
  120. {
  121. CGSize size = self.contentSize;
  122. size.height = mj_contentH;
  123. self.contentSize = size;
  124. }
  125. - (CGFloat)mj_contentH
  126. {
  127. return self.contentSize.height;
  128. }
  129. @end
  130. #pragma clang diagnostic pop