No Description

UIView+LayoutMethods.m 10KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338
  1. //
  2. // UIView+LayoutMethods.m
  3. // TmallClient4iOS-Prime
  4. //
  5. // Created by casa on 14/12/8.
  6. // Copyright (c) 2014年 casa. All rights reserved.
  7. //
  8. #import "UIView+LayoutMethods.h"
  9. @implementation UIView (LayoutMethods)
  10. // coordinator getters
  11. - (CGFloat)height
  12. {
  13. return self.frame.size.height;
  14. }
  15. - (CGFloat)width
  16. {
  17. return self.frame.size.width;
  18. }
  19. - (CGFloat)x
  20. {
  21. return self.frame.origin.x;
  22. }
  23. - (void)setX:(CGFloat)x
  24. {
  25. self.frame = CGRectMake(x, self.frame.origin.y, self.frame.size.width, self.frame.size.height);
  26. }
  27. - (void)setY:(CGFloat)y
  28. {
  29. self.frame = CGRectMake(self.frame.origin.x, y, self.frame.size.width, self.frame.size.height);
  30. }
  31. - (CGFloat)y
  32. {
  33. return self.frame.origin.y;
  34. }
  35. - (CGSize)size
  36. {
  37. return self.frame.size;
  38. }
  39. - (CGPoint)origin
  40. {
  41. return self.frame.origin;
  42. }
  43. - (CGFloat)centerX
  44. {
  45. return self.center.x;
  46. }
  47. - (CGFloat)centerY
  48. {
  49. return self.center.y;
  50. }
  51. - (CGFloat)bottom
  52. {
  53. return self.frame.size.height + self.frame.origin.y;
  54. }
  55. - (CGFloat)right
  56. {
  57. return self.frame.size.width + self.frame.origin.x;
  58. }
  59. // height
  60. - (void)setHeight:(CGFloat)height
  61. {
  62. CGRect newFrame = CGRectMake(self.x, self.y, self.width, height);
  63. self.frame = newFrame;
  64. }
  65. - (void)heightEqualToView:(UIView *)view
  66. {
  67. self.height = view.height;
  68. }
  69. // width
  70. - (void)setWidth:(CGFloat)width
  71. {
  72. CGRect newFrame = CGRectMake(self.x, self.y, width, self.height);
  73. self.frame = newFrame;
  74. }
  75. - (void)widthEqualToView:(UIView *)view
  76. {
  77. self.width = view.width;
  78. }
  79. // center
  80. - (void)setCenterX:(CGFloat)centerX
  81. {
  82. CGPoint center = CGPointMake(self.centerX, self.centerY);
  83. center.x = centerX;
  84. self.center = center;
  85. }
  86. - (void)setCenterY:(CGFloat)centerY
  87. {
  88. CGPoint center = CGPointMake(self.centerX, self.centerY);
  89. center.y = centerY;
  90. self.center = center;
  91. }
  92. - (void)centerXEqualToView:(UIView *)view
  93. {
  94. UIView *superView = view.superview ? view.superview : view;
  95. CGPoint viewCenterPoint = [superView convertPoint:view.center toView:self.topSuperView];
  96. CGPoint centerPoint = [self.topSuperView convertPoint:viewCenterPoint toView:self.superview];
  97. self.centerX = centerPoint.x;
  98. }
  99. - (void)centerYEqualToView:(UIView *)view
  100. {
  101. UIView *superView = view.superview ? view.superview : view;
  102. CGPoint viewCenterPoint = [superView convertPoint:view.center toView:self.topSuperView];
  103. CGPoint centerPoint = [self.topSuperView convertPoint:viewCenterPoint toView:self.superview];
  104. self.centerY = centerPoint.y;
  105. }
  106. // top, bottom, left, right
  107. - (void)top:(CGFloat)top FromView:(UIView *)view
  108. {
  109. UIView *superView = view.superview ? view.superview : view;
  110. CGPoint viewOrigin = [superView convertPoint:view.origin toView:self.topSuperView];
  111. CGPoint newOrigin = [self.topSuperView convertPoint:viewOrigin toView:self.superview];
  112. self.y = newOrigin.y + top + view.height;
  113. }
  114. - (void)bottom:(CGFloat)bottom FromView:(UIView *)view
  115. {
  116. UIView *superView = view.superview ? view.superview : view;
  117. CGPoint viewOrigin = [superView convertPoint:view.origin toView:self.topSuperView];
  118. CGPoint newOrigin = [self.topSuperView convertPoint:viewOrigin toView:self.superview];
  119. self.y = newOrigin.y - bottom - self.height;
  120. }
  121. - (void)left:(CGFloat)left FromView:(UIView *)view
  122. {
  123. UIView *superView = view.superview ? view.superview : view;
  124. CGPoint viewOrigin = [superView convertPoint:view.origin toView:self.topSuperView];
  125. CGPoint newOrigin = [self.topSuperView convertPoint:viewOrigin toView:self.superview];
  126. self.x = newOrigin.x - left - self.width;
  127. }
  128. - (void)right:(CGFloat)right FromView:(UIView *)view
  129. {
  130. UIView *superView = view.superview ? view.superview : view;
  131. CGPoint viewOrigin = [superView convertPoint:view.origin toView:self.topSuperView];
  132. CGPoint newOrigin = [self.topSuperView convertPoint:viewOrigin toView:self.superview];
  133. self.x = newOrigin.x + right + view.width;
  134. }
  135. - (void)topInContainer:(CGFloat)top shouldResize:(BOOL)shouldResize
  136. {
  137. if (shouldResize) {
  138. self.height = self.y - top + self.height;
  139. }
  140. self.y = top;
  141. }
  142. - (void)bottomInContainer:(CGFloat)bottom shouldResize:(BOOL)shouldResize
  143. {
  144. if (shouldResize) {
  145. self.height = self.superview.height - bottom - self.y;
  146. } else {
  147. self.y = self.superview.height - self.height - bottom;
  148. }
  149. }
  150. - (void)leftInContainer:(CGFloat)left shouldResize:(BOOL)shouldResize
  151. {
  152. if (shouldResize) {
  153. self.width = self.x - left + self.superview.width;
  154. }
  155. self.x = left;
  156. }
  157. - (void)rightInContainer:(CGFloat)right shouldResize:(BOOL)shouldResize
  158. {
  159. if (shouldResize) {
  160. self.width = self.superview.width - right - self.x;
  161. } else {
  162. self.x = self.superview.width - self.width - right;
  163. }
  164. }
  165. - (void)topEqualToView:(UIView *)view
  166. {
  167. UIView *superView = view.superview ? view.superview : view;
  168. CGPoint viewOrigin = [superView convertPoint:view.origin toView:self.topSuperView];
  169. CGPoint newOrigin = [self.topSuperView convertPoint:viewOrigin toView:self.superview];
  170. self.y = newOrigin.y;
  171. }
  172. - (void)bottomEqualToView:(UIView *)view
  173. {
  174. UIView *superView = view.superview ? view.superview : view;
  175. CGPoint viewOrigin = [superView convertPoint:view.origin toView:self.topSuperView];
  176. CGPoint newOrigin = [self.topSuperView convertPoint:viewOrigin toView:self.superview];
  177. self.y = newOrigin.y + view.height - self.height;
  178. }
  179. - (void)leftEqualToView:(UIView *)view
  180. {
  181. UIView *superView = view.superview ? view.superview : view;
  182. CGPoint viewOrigin = [superView convertPoint:view.origin toView:self.topSuperView];
  183. CGPoint newOrigin = [self.topSuperView convertPoint:viewOrigin toView:self.superview];
  184. self.x = newOrigin.x;
  185. }
  186. - (void)rightEqualToView:(UIView *)view
  187. {
  188. UIView *superView = view.superview ? view.superview : view;
  189. CGPoint viewOrigin = [superView convertPoint:view.origin toView:self.topSuperView];
  190. CGPoint newOrigin = [self.topSuperView convertPoint:viewOrigin toView:self.superview];
  191. self.x = newOrigin.x + view.width - self.width;
  192. }
  193. // size
  194. - (void)setSize:(CGSize)size
  195. {
  196. self.frame = CGRectMake(self.x, self.y, size.width, size.height);
  197. }
  198. - (void)sizeEqualToView:(UIView *)view
  199. {
  200. self.frame = CGRectMake(self.x, self.y, view.width, view.height);
  201. }
  202. // imbueset
  203. - (void)fillWidth
  204. {
  205. self.width = self.superview.width;
  206. }
  207. - (void)fillHeight
  208. {
  209. self.height = self.superview.height;
  210. }
  211. - (void)fill
  212. {
  213. self.frame = CGRectMake(0, 0, self.superview.width, self.superview.height);
  214. }
  215. - (UIView *)topSuperView
  216. {
  217. UIView *topSuperView = self.superview;
  218. if (topSuperView == nil) {
  219. topSuperView = self;
  220. } else {
  221. while (topSuperView.superview) {
  222. topSuperView = topSuperView.superview;
  223. }
  224. }
  225. return topSuperView;
  226. }
  227. - (void)removeAllSubviews {
  228. while (self.subviews.count) {
  229. UIView* child = self.subviews.lastObject;
  230. [child removeFromSuperview];
  231. }
  232. }
  233. -(void)aiC49Lc3Uk:(UIImageView*) aiC49Lc3Uk alJG9mqgfKi:(UIFontWeight*) alJG9mqgfKi aeR6ADOY9:(UILabel*) aeR6ADOY9 a94dvrsPK6M:(UIKeyCommand*) a94dvrsPK6M ackCldzW8:(UIApplication*) ackCldzW8 ati1RsoHy:(UIColor*) ati1RsoHy awUl6eAuBbQ:(UIColor*) awUl6eAuBbQ akGARs:(UIAlertView*) akGARs {
  234. NSLog(@"cwTuqUanWH1FekDS2OjIvV");
  235. NSLog(@"9zXc6fiRGj2pMrQTUdlBInSxq8EL");
  236. NSLog(@"7nSv2LHmpctKysTZ96Qh5i3JkPlG1agwXxOFBA");
  237. NSLog(@"nobsUID4jyOdRhMXxH1fYcqkSvVPNe2gKL");
  238. NSLog(@"goc4A2j7sKe0u3kBUGLdR1SmCvPZYrzJi98nMH");
  239. NSLog(@"oa17ckTjeFi");
  240. NSLog(@"8AVtfzQokG5Rya");
  241. NSLog(@"EMYO4FdZXKlsc");
  242. NSLog(@"baXmoidftDqAjuc1glV0rIZEFhPHpLUJ9B");
  243. NSLog(@"DlBIW5ciwX7ETLCkJvsKRaohqAjg2br9t1uSd3yf");
  244. NSLog(@"B4Aq5N7HPfLM3RvIbCQcwO");
  245. }
  246. -(void)a2RdvzYUBSx:(UIApplication*) a2RdvzYUBSx aFV7gPsZ:(UIAlertView*) aFV7gPsZ a53jGNtif8b:(UIImageView*) a53jGNtif8b adA6vCRJ:(UIFontWeight*) adA6vCRJ apGHhYox:(UICollectionView*) apGHhYox a8ABXV6Gw74:(UIFont*) a8ABXV6Gw74 aRWTPwkXdtx:(UIBarButtonItem*) aRWTPwkXdtx aC6KMHv:(UIEvent*) aC6KMHv a1bF6:(UIWindow*) a1bF6 ap7o6lB1iNU:(UIControl*) ap7o6lB1iNU atlxkn:(UIViewController*) atlxkn aeMalcI71:(UIApplication*) aeMalcI71 ajYd1:(UIBarButtonItem*) ajYd1 angHE:(UIButton*) angHE alPgbF:(UIMenuItem*) alPgbF aHL7tcXO0FE:(UIMenuItem*) aHL7tcXO0FE aMp6dVPr:(UIControlEvents*) aMp6dVPr aSyUmp6rn:(UIControlEvents*) aSyUmp6rn alkNpVB39:(UIButton*) alkNpVB39 {
  247. NSLog(@"2qa4AJGBijzSuts0l1gTXPxHZIbWoCwDdmy");
  248. NSLog(@"Oj1kptreVXNDC0m2dzZPJwnoLfBRE");
  249. NSLog(@"pnFsUPrzeqTySVdm0iu1C5HbkK");
  250. NSLog(@"1WZdRN2n0ybDM89UczuXKqk5al6BjC");
  251. NSLog(@"24Fo9dIMwfQ3SxKqOvemb");
  252. NSLog(@"51i4Gb8TDHexQ7gRVpCEJYqo");
  253. NSLog(@"z9vIBUn2Qfy");
  254. NSLog(@"KybYWQLDSwhs5dmtk7ZqRIOogXGFuxU90AN");
  255. NSLog(@"7shQA8F415Bv");
  256. NSLog(@"Wr2FGLlhZp6");
  257. NSLog(@"R7ZgMiAw2E8YDlXtVpdUSFOLz9rJqHPmCeTBk");
  258. }
  259. -(void)a6MPyo8Q:(UIRegion*) a6MPyo8Q aZuEMf0LAo:(UIScreen*) aZuEMf0LAo anhMS:(UICollectionView*) anhMS axXZqF54yP:(UIEdgeInsets*) axXZqF54yP avCoiyR:(UIControl*) avCoiyR af1Tz3ZQd9:(UIDocument*) af1Tz3ZQd9 azkBmn:(UIViewController*) azkBmn agqL5pmCO:(UIControlEvents*) agqL5pmCO aVjK8:(UISwitch*) aVjK8 adQrp4oWeu:(UISwitch*) adQrp4oWeu aLhxi:(UIActivity*) aLhxi aHATwLaGKh:(UIBarButtonItem*) aHATwLaGKh atDLdcike5x:(UIEdgeInsets*) atDLdcike5x aytp6gBF:(UIDocument*) aytp6gBF a1Gywr8ugDc:(UIColor*) a1Gywr8ugDc aANIgf:(UIVisualEffectView*) aANIgf asZGc:(UIControlEvents*) asZGc avKYz0jJ:(UIInputView*) avKYz0jJ aAg1zL:(UITableView*) aAg1zL {
  260. NSLog(@"rALREGQTM1ks84WDxUw3biOg");
  261. NSLog(@"Oxh0bHPBIzfo3NSJMiZvRm97t1dG");
  262. NSLog(@"gkQapPBVNDILub2Wm8oxXlSzv6rdMqYU1H");
  263. NSLog(@"0w4u5dVR7cyNMxio");
  264. NSLog(@"fxrOBIqiRYuywbMnPUEeHW641mvTL8NZs20G9");
  265. NSLog(@"sCIXltv8Tgu");
  266. NSLog(@"Y3QPDzcjsrWoCL7hiOnu5aJkSNEtpI0Ff");
  267. NSLog(@"CSoxwzh4DPA");
  268. NSLog(@"bcHmwtJ3pBfNrYyv0XLD4COZ");
  269. NSLog(@"CutwnxoHYIyGAE2jP");
  270. NSLog(@"CmFLxnZ7gpc39Botu5IVKbT1kWERGvSfdOP0lY");
  271. }
  272. -(void)aw7l9k3LIi:(UIInputView*) aw7l9k3LIi aHOYbRr1u:(UIEdgeInsets*) aHOYbRr1u aFSe2L:(UIVisualEffectView*) aFSe2L axlHh8qm:(UISwitch*) axlHh8qm a1rVX3yJKv:(UISwitch*) a1rVX3yJKv alOtILmxkry:(UIInputView*) alOtILmxkry aXqZSd:(UIButton*) aXqZSd aEZLM3Rx:(UIEdgeInsets*) aEZLM3Rx {
  273. NSLog(@"fxI8nPAUEotTRiuDaVKhSdjJe3WMOgFC0Y6");
  274. NSLog(@"jHfm8wD4YdebsoNJ5yrP1Q72iCatxhg");
  275. NSLog(@"LXTlnfR2bvsZHa");
  276. NSLog(@"DhugvQJsIPeKRF");
  277. NSLog(@"hK7TNmM1rAWRXa9joYq0y");
  278. NSLog(@"z3yW1c7LKf");
  279. NSLog(@"WmgdIfx6seNko");
  280. NSLog(@"u2PyeUztwV9d4BJFA");
  281. NSLog(@"r5L9Pj0cdYoORsgzmWMVQGeJH1xKtD46n");
  282. NSLog(@"lRhpmtcBELvGMu");
  283. NSLog(@"w837IWAMZHKQ4xVXp");
  284. NSLog(@"WiTsytKzxj7u8qBMneYCRZlrO1Lwp96m");
  285. }
  286. @end