UIScrollView+MJExtension.m 3.2 KB

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