UIView+ZFFrame.m 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. //
  2. // UIView+ZFFrame.m
  3. // ZFPlayer
  4. //
  5. // Copyright (c) 2016年 任子丰 ( http://github.com/renzifeng )
  6. //
  7. // Permission is hereby granted, free of charge, to any person obtaining a copy
  8. // of this software and associated documentation files (the "Software"), to deal
  9. // in the Software without restriction, including without limitation the rights
  10. // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  11. // copies of the Software, and to permit persons to whom the Software is
  12. // furnished to do so, subject to the following conditions:
  13. //
  14. // The above copyright notice and this permission notice shall be included in
  15. // all copies or substantial portions of the Software.
  16. //
  17. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  18. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  19. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  20. // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  21. // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  22. // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  23. // THE SOFTWARE.
  24. #import "UIView+ZFFrame.h"
  25. @implementation UIView (ZFFrame)
  26. - (CGFloat)zf_x {
  27. return self.frame.origin.x;
  28. }
  29. - (void)setZf_x:(CGFloat)zf_x {
  30. CGRect newFrame = self.frame;
  31. newFrame.origin.x = zf_x;
  32. self.frame = newFrame;
  33. }
  34. - (CGFloat)zf_y {
  35. return self.frame.origin.y;
  36. }
  37. - (void)setZf_y:(CGFloat)zf_y {
  38. CGRect newFrame = self.frame;
  39. newFrame.origin.y = zf_y;
  40. self.frame = newFrame;
  41. }
  42. - (CGFloat)zf_width {
  43. return CGRectGetWidth(self.bounds);
  44. }
  45. - (void)setZf_width:(CGFloat)zf_width {
  46. CGRect newFrame = self.frame;
  47. newFrame.size.width = zf_width;
  48. self.frame = newFrame;
  49. }
  50. - (CGFloat)zf_height {
  51. return CGRectGetHeight(self.bounds);
  52. }
  53. - (void)setZf_height:(CGFloat)zf_height {
  54. CGRect newFrame = self.frame;
  55. newFrame.size.height = zf_height;
  56. self.frame = newFrame;
  57. }
  58. - (CGFloat)zf_top {
  59. return self.frame.origin.y;
  60. }
  61. - (void)setZf_top:(CGFloat)zf_top {
  62. CGRect newFrame = self.frame;
  63. newFrame.origin.y = zf_top;
  64. self.frame = newFrame;
  65. }
  66. - (CGFloat)zf_bottom {
  67. return self.frame.origin.y + self.frame.size.height;
  68. }
  69. - (void)setZf_bottom:(CGFloat)zf_bottom {
  70. CGRect newFrame = self.frame;
  71. newFrame.origin.y = zf_bottom - self.frame.size.height;
  72. self.frame = newFrame;
  73. }
  74. - (CGFloat)zf_left {
  75. return self.frame.origin.x;
  76. }
  77. - (void)setZf_left:(CGFloat)zf_left {
  78. CGRect newFrame = self.frame;
  79. newFrame.origin.x = zf_left;
  80. self.frame = newFrame;
  81. }
  82. - (CGFloat)zf_right {
  83. return self.frame.origin.x + self.frame.size.width;
  84. }
  85. - (void)setZf_right:(CGFloat)zf_right {
  86. CGRect newFrame = self.frame;
  87. newFrame.origin.x = zf_right - self.frame.size.width;
  88. self.frame = newFrame;
  89. }
  90. - (CGFloat)zf_centerX {
  91. return self.center.x;
  92. }
  93. - (void)setZf_centerX:(CGFloat)zf_centerX {
  94. CGPoint newCenter = self.center;
  95. newCenter.x = zf_centerX;
  96. self.center = newCenter;
  97. }
  98. - (CGFloat)zf_centerY {
  99. return self.center.y;
  100. }
  101. - (void)setZf_centerY:(CGFloat)zf_centerY {
  102. CGPoint newCenter = self.center;
  103. newCenter.y = zf_centerY;
  104. self.center = newCenter;
  105. }
  106. - (CGPoint)zf_origin {
  107. return self.frame.origin;
  108. }
  109. - (void)setZf_origin:(CGPoint)zf_origin {
  110. CGRect newFrame = self.frame;
  111. newFrame.origin = zf_origin;
  112. self.frame = newFrame;
  113. }
  114. - (CGSize)zf_size {
  115. return self.frame.size;
  116. }
  117. - (void)setZf_size:(CGSize)zf_size {
  118. CGRect newFrame = self.frame;
  119. newFrame.size = zf_size;
  120. self.frame = newFrame;
  121. }
  122. @end