UIScrollView+MJExtension.m 3.1 KB

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