UIView+Frame.m 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217
  1. //
  2. // UIView+Frame.m
  3. // WZLCodeLibrary
  4. //
  5. // Created by wzl on 15/3/23.
  6. // Copyright (c) 2015年 Weng-Zilin. All rights reserved.
  7. //
  8. #import "UIView+Frame.h"
  9. @implementation UIView (Frame)
  10. - (void)setX:(CGFloat)x
  11. {
  12. CGRect frame = self.frame;
  13. frame.origin.x = x;
  14. self.frame = frame;
  15. }
  16. - (CGFloat)x
  17. {
  18. return self.frame.origin.x;
  19. }
  20. - (void)setY:(CGFloat)y
  21. {
  22. CGRect frame = self.frame;
  23. frame.origin.y = y;
  24. self.frame = frame;
  25. }
  26. - (CGFloat)y
  27. {
  28. return self.frame.origin.y;
  29. }
  30. - (void)setOrigin:(CGPoint)origin
  31. {
  32. CGRect frame = self.frame;
  33. frame.origin = origin;
  34. self.frame = frame;
  35. }
  36. - (CGPoint)origin
  37. {
  38. return self.frame.origin;
  39. }
  40. - (void)setWidth:(CGFloat)width
  41. {
  42. CGRect frame = self.frame;
  43. frame.size.width = width;
  44. self.frame = frame;
  45. }
  46. - (CGFloat)width
  47. {
  48. return self.frame.size.width;
  49. }
  50. - (void)setHeight:(CGFloat)height
  51. {
  52. CGRect frame = self.frame;
  53. frame.size.height = height;
  54. self.frame = frame;
  55. }
  56. - (CGFloat)height
  57. {
  58. return self.frame.size.height;
  59. }
  60. - (void)setSize:(CGSize)size
  61. {
  62. CGRect frame = self.frame;
  63. frame.size = size;
  64. self.frame = frame;
  65. }
  66. - (CGSize)size
  67. {
  68. return self.frame.size;
  69. }
  70. - (void)setBottom:(CGFloat)bottom
  71. {
  72. CGRect frame = self.frame;
  73. frame.origin.y = bottom - frame.size.height;
  74. self.frame = frame;
  75. }
  76. - (CGFloat)bottom
  77. {
  78. return CGRectGetMaxY(self.frame);
  79. }
  80. - (CGFloat)tail
  81. {
  82. return CGRectGetMaxX(self.frame);
  83. }
  84. - (void)setTail:(CGFloat)tail
  85. {
  86. CGRect frame = self.frame;
  87. frame.origin.x = tail - frame.size.width;
  88. self.frame = frame;
  89. }
  90. - (void)setMiddleX:(CGFloat)middleX
  91. {
  92. CGRect frame = self.frame;
  93. frame.origin.x = middleX - frame.size.width / 2;
  94. self.frame = frame;
  95. }
  96. - (CGFloat)middleX
  97. {
  98. return CGRectGetMidX(self.frame);
  99. }
  100. - (void)setMiddleY:(CGFloat)middleY
  101. {
  102. CGRect frame = self.frame;
  103. frame.origin.y = middleY - frame.size.height / 2 ;
  104. self.frame = frame;
  105. }
  106. - (CGFloat)middleY
  107. {
  108. return CGRectGetMidY(self.frame);
  109. }
  110. @end
  111. @implementation UIView(formatter)
  112. -(void)setRound
  113. {
  114. self.layer.masksToBounds = YES;
  115. self.layer.cornerRadius = self.width/2.0;
  116. }
  117. -(void)boardWid:(CGFloat)width Color:(UIColor*)color
  118. {
  119. [self.layer setBorderWidth:width];
  120. [self.layer setBorderColor:color.CGColor];
  121. [self.layer setMasksToBounds:YES];
  122. [self.layer setCornerRadius:6];
  123. }
  124. -(void)borderCornorRadios:(CGFloat)cornor
  125. {
  126. self.layer.masksToBounds = YES;
  127. self.layer.cornerRadius = cornor;
  128. }
  129. -(void)borderColor:(UIColor *)color width:(CGFloat)wid cornorRadios:(CGFloat)cornor
  130. {
  131. self.layer.masksToBounds = YES;
  132. self.layer.cornerRadius = cornor;
  133. self.layer.borderWidth = wid;
  134. self.layer.borderColor = color.CGColor;
  135. }
  136. -(void)addViewWithRect:(CGRect)re Color:(UIColor*)color
  137. {
  138. UIView *v = [[UIView alloc] initWithFrame:re];
  139. [v setBackgroundColor:color];
  140. [self.superview addSubview:v];
  141. }
  142. -(void)addViewWithRect:(CGRect)re
  143. {
  144. [self addViewWithRect:re Color:kLineColor];
  145. }
  146. -(void)addSelfViewWithRect:(CGRect)re Color:(UIColor*)color
  147. {
  148. UIView *v = [[UIView alloc] initWithFrame:re];
  149. [v setBackgroundColor:color];
  150. [self addSubview:v];
  151. }
  152. -(void)scale:(CGFloat)rate
  153. {
  154. self.transform = CGAffineTransformScale(CGAffineTransformIdentity, rate,rate);
  155. }
  156. @end