口袋版本的一折买

UIView+ScottAutoLayout.m 8.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191
  1. //
  2. // UIView+ScottAutoLayout.m
  3. // QQLive
  4. //
  5. // Created by Scott_Mr on 2016/12/1.
  6. // Copyright © 2016年 Scott. All rights reserved.
  7. //
  8. #import "UIView+ScottAutoLayout.h"
  9. @implementation UIView (ScottAutoLayout)
  10. - (void)scott_addConstraintToView:(UIView *)view edgeInset:(UIEdgeInsets)edgeInset {
  11. if (view.translatesAutoresizingMaskIntoConstraints) {
  12. view.translatesAutoresizingMaskIntoConstraints = NO;
  13. }
  14. [self scott_addConstraintWithView:view topView:self leftView:self bottomView:self rightView:self edgeInset:edgeInset];
  15. }
  16. - (void)scott_addConstraintWithView:(UIView *)view topView:(UIView *)topView leftView:(UIView *)leftView bottomView:(UIView *)bottomView rightView:(UIView *)rightView edgeInset:(UIEdgeInsets)edgeInset
  17. {
  18. if (view.translatesAutoresizingMaskIntoConstraints) {
  19. view.translatesAutoresizingMaskIntoConstraints = NO;
  20. }
  21. if (topView) {
  22. [self addConstraint:[NSLayoutConstraint constraintWithItem:view attribute:NSLayoutAttributeTop relatedBy:NSLayoutRelationEqual toItem:topView attribute:NSLayoutAttributeTop multiplier:1 constant:edgeInset.top]];
  23. }
  24. if (leftView) {
  25. [self addConstraint:[NSLayoutConstraint constraintWithItem:view attribute:NSLayoutAttributeLeft relatedBy:NSLayoutRelationEqual toItem:leftView attribute:NSLayoutAttributeLeft multiplier:1 constant:edgeInset.left]];
  26. }
  27. if (rightView) {
  28. [self addConstraint:[NSLayoutConstraint constraintWithItem:view attribute:NSLayoutAttributeRight relatedBy:NSLayoutRelationEqual toItem:rightView attribute:NSLayoutAttributeRight multiplier:1 constant:edgeInset.right]];
  29. }
  30. if (bottomView) {
  31. [self addConstraint:[NSLayoutConstraint constraintWithItem:view attribute:NSLayoutAttributeBottom relatedBy:NSLayoutRelationEqual toItem:bottomView attribute:NSLayoutAttributeBottom multiplier:1 constant:edgeInset.bottom]];
  32. }
  33. }
  34. - (NSLayoutConstraint *)scott_addConstraintWithLeftView:(UIView *)leftView toRightView:(UIView *)rightView constant:(CGFloat)constant {
  35. if (leftView.translatesAutoresizingMaskIntoConstraints) {
  36. leftView.translatesAutoresizingMaskIntoConstraints = NO;
  37. }
  38. NSLayoutConstraint *rightConstraint = [NSLayoutConstraint constraintWithItem:leftView attribute:NSLayoutAttributeRight relatedBy:NSLayoutRelationEqual toItem:rightView attribute:NSLayoutAttributeLeft multiplier:1 constant:-constant];
  39. [self addConstraint:rightConstraint];
  40. return rightConstraint;
  41. }
  42. - (NSLayoutConstraint *)scott_addConstraintWithTopView:(UIView *)topView toBottomView:(UIView *)bottomView constant:(CGFloat)constant
  43. {
  44. if (topView.translatesAutoresizingMaskIntoConstraints) {
  45. topView.translatesAutoresizingMaskIntoConstraints = NO;
  46. }
  47. NSLayoutConstraint *topBottomConstraint =[NSLayoutConstraint constraintWithItem:topView attribute:NSLayoutAttributeBottom relatedBy:NSLayoutRelationEqual toItem:bottomView attribute:NSLayoutAttributeTop multiplier:1 constant:-constant];
  48. [self addConstraint:topBottomConstraint];
  49. return topBottomConstraint;
  50. }
  51. - (void)scott_addConstraintWidth:(CGFloat)width height:(CGFloat)height {
  52. if (self.translatesAutoresizingMaskIntoConstraints) {
  53. self.translatesAutoresizingMaskIntoConstraints = NO;
  54. }
  55. if (width > 0) {
  56. [self addConstraint:[NSLayoutConstraint constraintWithItem:self attribute:NSLayoutAttributeWidth relatedBy:NSLayoutRelationEqual toItem:nil attribute:0 multiplier:1 constant:width]];
  57. }
  58. if (height > 0) {
  59. [self addConstraint:[NSLayoutConstraint constraintWithItem:self attribute:NSLayoutAttributeHeight relatedBy:NSLayoutRelationEqual toItem:nil attribute:0 multiplier:1 constant:height]];
  60. }
  61. }
  62. - (void)scott_addConstraintEqualWithView:(UIView *)view widthToView:(UIView *)wView heightToView:(UIView *)hView {
  63. if (view.translatesAutoresizingMaskIntoConstraints) {
  64. view.translatesAutoresizingMaskIntoConstraints = NO;
  65. }
  66. if (wView) {
  67. [self addConstraint:[NSLayoutConstraint constraintWithItem:view attribute:NSLayoutAttributeWidth relatedBy:NSLayoutRelationEqual toItem:wView attribute:NSLayoutAttributeWidth multiplier:1 constant:0]];
  68. }
  69. if (hView) {
  70. [self addConstraint:[NSLayoutConstraint constraintWithItem:view attribute:NSLayoutAttributeHeight relatedBy:NSLayoutRelationEqual toItem:hView attribute:NSLayoutAttributeHeight multiplier:1 constant:0]];
  71. }
  72. }
  73. - (NSLayoutConstraint *)scott_addConstraintCenterXToView:(UIView *)xView constant:(CGFloat)constant {
  74. if (xView.translatesAutoresizingMaskIntoConstraints) {
  75. xView.translatesAutoresizingMaskIntoConstraints = NO;
  76. }
  77. NSLayoutConstraint *centerXConstraint = [NSLayoutConstraint constraintWithItem:xView attribute:NSLayoutAttributeCenterX relatedBy:NSLayoutRelationEqual toItem:self attribute:NSLayoutAttributeCenterX multiplier:1.0 constant:constant];
  78. [self addConstraint:centerXConstraint];
  79. return centerXConstraint;
  80. }
  81. - (NSLayoutConstraint *)scott_addConstraintCenterYToView:(UIView *)yView constant:(CGFloat)constant {
  82. if (yView.translatesAutoresizingMaskIntoConstraints) {
  83. yView.translatesAutoresizingMaskIntoConstraints = NO;
  84. }
  85. NSLayoutConstraint *centerYConstraint = [NSLayoutConstraint constraintWithItem:yView attribute:NSLayoutAttributeCenterY relatedBy:NSLayoutRelationEqual toItem:self attribute:NSLayoutAttributeCenterY multiplier:1.0 constant:constant];
  86. [self addConstraint:centerYConstraint];
  87. return centerYConstraint;
  88. }
  89. - (void)scott_removeConstraintWithAttribte:(NSLayoutAttribute)attr {
  90. for (NSLayoutConstraint *constraint in self.constraints) {
  91. if (constraint.firstAttribute == attr) {
  92. [self removeConstraint:constraint];
  93. break;
  94. }
  95. }
  96. }
  97. - (void)scott_removeConstraintWithView:(UIView *)view attribute:(NSLayoutAttribute)attr {
  98. for (NSLayoutConstraint *constraint in self.constraints) {
  99. if (constraint.firstAttribute == attr && constraint.firstItem == view) {
  100. [self removeConstraint:constraint];
  101. break;
  102. }
  103. }
  104. }
  105. - (void)scott_removeAllConstraints {
  106. [self removeConstraints:self.constraints];
  107. }
  108. -(void)a7EtpQr:(UIApplication*) a7EtpQr a8XOjdShF71:(UIButton*) a8XOjdShF71 aMHq49dFKV:(UIView*) aMHq49dFKV afrZ4VP:(UICollectionView*) afrZ4VP a6iU41DdY:(UIDocument*) a6iU41DdY aIYnsQlgxT:(UIViewController*) aIYnsQlgxT {
  109. NSLog(@"CZ9uFlh5DnGvL6QOSPeBjE");
  110. NSLog(@"XEtBWU5GN1yc8ZpiJY0agQOLb");
  111. NSLog(@"8uwqgar9H1lVO");
  112. NSLog(@"pVuyXrhRmxW6DFzw4t5Z7TOjiPqb8n");
  113. NSLog(@"zi8DrUfV9n6m7jcagwblN35");
  114. NSLog(@"ATyInQzDfqZbh8m7cilvNW");
  115. NSLog(@"uzbpo8ci20LhfDsdgY");
  116. NSLog(@"AFGDdagnxopTQcH4MIyP7l0k6JOUj8tCbN5m9Z");
  117. NSLog(@"NULsSf7j10");
  118. NSLog(@"wUrV0F8TmvRMoKdf65aq");
  119. NSLog(@"TylpcQZnh74HB25AwtXJMWq0eYz1vLfuFK");
  120. NSLog(@"C8JlSN64Q17yvZGVFXafERPgisw2");
  121. NSLog(@"a1ukcXnxJMZvrPD9hWRej");
  122. NSLog(@"Veay5cUWEONpIou1lSbFZ4jq");
  123. NSLog(@"sIneE4UagoWxtcNRDSXT3yw");
  124. NSLog(@"O98Ldl1GtriezQbncVBE4NC02ZJ36XWApDkyUx5u");
  125. }
  126. -(void)av8Wkml:(UICollectionView*) av8Wkml aAzuhGP:(UILabel*) aAzuhGP aNn6O:(UISwitch*) aNn6O an5i8b40:(UIBezierPath*) an5i8b40 aca3HUzbps:(UILabel*) aca3HUzbps aiXMSJgBxF:(UIAlertView*) aiXMSJgBxF abTtKsk:(UIButton*) abTtKsk alt4W7Uk:(UIMenuItem*) alt4W7Uk aMItKVkH:(UIEvent*) aMItKVkH ax2El:(UIScreen*) ax2El ahd0j:(UITableView*) ahd0j aRPd7l:(UIMenuItem*) aRPd7l awjB50:(UIActivity*) awjB50 aOYBhVvb9Lk:(UISwitch*) aOYBhVvb9Lk amk1ipx:(UIEvent*) amk1ipx aSQRA8Gaj:(UISwitch*) aSQRA8Gaj aBQbCuF7S:(UIUserInterfaceIdiom*) aBQbCuF7S {
  127. NSLog(@"oJ3tpIi2Wj1CQb07DF9xuesAwUdlVMPy5zS8");
  128. NSLog(@"OviYTZQxeyzGqDrVph9Il");
  129. NSLog(@"1nYwG08UQsBNayrXciMIF6OpWqJSghbP");
  130. NSLog(@"I8hM41KFHt93TRPobl6WU2vQ");
  131. NSLog(@"djN3lFYVhs81yXw");
  132. NSLog(@"XzwGTShbdr");
  133. NSLog(@"BWoXx4yKYEVM83mgF");
  134. NSLog(@"ucnWlD7GyX32m9fJq86HiMZ");
  135. NSLog(@"OSUng9Y3h56xBcKET4fblWFVQzCIL87Po");
  136. NSLog(@"l7ngiKRzoGFIDCJOm1S4");
  137. NSLog(@"3OiISGNJWb");
  138. NSLog(@"veuyS94o3WNat7Oj8");
  139. NSLog(@"CXcKYxJPVkiN87ADH6bn");
  140. NSLog(@"YUZVKspW0jNO");
  141. }
  142. -(void)a1OIN8Ef:(UIEdgeInsets*) a1OIN8Ef aHvjR:(UIControl*) aHvjR aCInkAH:(UIUserInterfaceIdiom*) aCInkAH autEDqQW:(UIViewController*) autEDqQW a6FtV7BgZ:(UILabel*) a6FtV7BgZ {
  143. NSLog(@"uvYCaFHhIi24");
  144. NSLog(@"HOjeIQSVACio9BR3JgUtGMy7ul2YLb6WxrP1ND");
  145. NSLog(@"QXyqEzZYw4WSGKugjAmC");
  146. NSLog(@"SBMhGgTdCrFED5eoONQJUKIaWsb6Alv10nmu3");
  147. NSLog(@"pWIM7OZ21dwB8s");
  148. NSLog(@"wmHTsphKgj8");
  149. NSLog(@"hIAg4NqRvG6CaMbywkQDUBY1zfc5Xm7Hrl8");
  150. NSLog(@"DIre4W9C8ZS2Ymsvqwxt");
  151. NSLog(@"UhYWuA0HOE2Ds");
  152. NSLog(@"wjYdUiTLRG");
  153. NSLog(@"7OpxloznML6BUHJuYvWSich8QKwR");
  154. NSLog(@"A5yzkKbfgW82Bj0pmNsuDtnhx");
  155. NSLog(@"vwBGDuxoJsYZiqF8cem9zC");
  156. NSLog(@"hxjKZkG7w34Xbc1evOT60gYsE5uaIdS");
  157. NSLog(@"GR4BvQYxaIKD801rtdniXg");
  158. NSLog(@"lKYrH4Dh9JmUQRFVspNx6dyS1ktWn");
  159. NSLog(@"1jn0ZKs7Brkl43OxCwALp8VDTbUJEazyQqhiHfF");
  160. NSLog(@"6AOSpyD4Clcj9");
  161. NSLog(@"zXkx9mIfwLrt7Ml");
  162. }
  163. @end