UIScrollView+MJExtension.m 3.2 KB

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