UIView+XMGExtension.m 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. //
  2. // UIView+XMGExtension.m
  3. // 3期-百思不得姐
  4. //
  5. // Created by xiaomage on 15/9/2.
  6. // Copyright (c) 2015年 xiaomage. All rights reserved.
  7. //
  8. #import "UIView+XMGExtension.h"
  9. @implementation UIView (XMGExtension)
  10. + (instancetype)viewFromXib
  11. {
  12. return [[[NSBundle mainBundle] loadNibNamed:NSStringFromClass(self) owner:nil options:nil] lastObject];
  13. }
  14. - (void)setX:(CGFloat)x
  15. {
  16. CGRect frame = self.frame;
  17. frame.origin.x = x;
  18. self.frame = frame;
  19. }
  20. - (CGFloat)x
  21. {
  22. return self.frame.origin.x;
  23. }
  24. - (void)setY:(CGFloat)y
  25. {
  26. CGRect frame = self.frame;
  27. frame.origin.y = y;
  28. self.frame = frame;
  29. }
  30. - (CGFloat)y
  31. {
  32. return self.frame.origin.y;
  33. }
  34. - (void)setWidth:(CGFloat)width
  35. {
  36. CGRect frame = self.frame;
  37. frame.size.width = width;
  38. self.frame = frame;
  39. }
  40. - (CGFloat)width
  41. {
  42. return self.frame.size.width;
  43. }
  44. - (void)setHeight:(CGFloat)height
  45. {
  46. CGRect frame = self.frame;
  47. frame.size.height = height;
  48. self.frame = frame;
  49. }
  50. - (CGFloat)height
  51. {
  52. return self.frame.size.height;
  53. }
  54. - (void)setCenterX:(CGFloat)centerX
  55. {
  56. CGPoint center = self.center;
  57. center.x = centerX;
  58. self.center = center;
  59. }
  60. - (CGFloat)centerX
  61. {
  62. return self.center.x;
  63. }
  64. - (void)setCenterY:(CGFloat)centerY
  65. {
  66. CGPoint center = self.center;
  67. center.y = centerY;
  68. self.center = center;
  69. }
  70. - (CGFloat)centerY
  71. {
  72. return self.center.y;
  73. }
  74. @end