UIView+Frame.m 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. //
  2. // UIView+Frame.m
  3. // Source
  4. //
  5. // Created by MD101 on 16/1/25.
  6. // Copyright © 2016年 yaocheng. All rights reserved.
  7. //
  8. #import "UIView+Frame.h"
  9. @implementation UIView (Frame)
  10. - (void)setX:(CGFloat)x{
  11. CGRect frame = self.frame;
  12. frame.origin.x = x;
  13. self.frame = frame;
  14. }
  15. - (CGFloat)x{
  16. return self.frame.origin.x;
  17. }
  18. - (void)setY:(CGFloat)y{
  19. CGRect frame = self.frame;
  20. frame.origin.y = y;
  21. self.frame = frame;
  22. }
  23. - (CGFloat)y{
  24. return self.frame.origin.y;
  25. }
  26. - (void)setWidth:(CGFloat)width{
  27. CGRect frame = self.frame;
  28. frame.size.width = width;
  29. self.frame = frame;
  30. }
  31. - (CGFloat)width{
  32. return self.frame.size.width;
  33. }
  34. - (void)setHeight:(CGFloat)height{
  35. CGRect frame = self.frame;
  36. frame.size.height = height;
  37. self.frame = frame;
  38. }
  39. - (CGFloat)height{
  40. return self.frame.size.height;
  41. }
  42. - (void)setCenterX:(CGFloat)centerX{
  43. CGPoint point = self.center;
  44. point.x = centerX;
  45. self.center = point;
  46. }
  47. - (CGFloat)centerX{
  48. return self.center.x;
  49. }
  50. - (void)setCenterY:(CGFloat)centerY{
  51. CGPoint point = self.center;
  52. point.y = centerY;
  53. self.center = point;
  54. }
  55. - (CGFloat)centerY{
  56. return self.center.y;
  57. }
  58. - (void)setSize:(CGSize)size{
  59. CGRect frame = self.frame;
  60. frame.size = size;
  61. self.frame = frame;
  62. }
  63. - (CGSize)size{
  64. return self.frame.size;
  65. }
  66. - (CGFloat)right
  67. {
  68. return self.frame.origin.x + self.frame.size.width;
  69. }
  70. - (void)setRight:(CGFloat)right
  71. {
  72. CGRect frame = self.frame;
  73. frame.origin.x = right - self.frame.size.width;
  74. self.frame = frame;
  75. }
  76. - (CGFloat)bottom
  77. {
  78. return self.frame.origin.y + self.frame.size.height;
  79. }
  80. - (void)setBottom:(CGFloat)bottom
  81. {
  82. CGRect frame = self.frame;
  83. frame.origin.y = bottom - self.frame.size.height;
  84. self.frame = frame;
  85. }
  86. @end