Simplified frame access and settings, and simplified frame access
I don't know who the original creator is because some programs have such expressions. Save it in the blog.
In the. m file
#import "UIView+MyFrameCategory.h"@implementation UIView (MyFrameCategory)//=================================- (void)setX:(CGFloat)x;{ CGRect tempFrame = self.frame; tempFrame.origin.x = x; self.frame = tempFrame;}- (CGFloat)x;{ return self.frame.origin.x;}//=================================- (void)setY:(CGFloat)y;{ CGRect tempFrame = self.frame; tempFrame.origin.y = y; self.frame = tempFrame;}- (CGFloat)y;{ return self.frame.origin.y;}//=================================- (void)setWidth:(CGFloat)width;{ CGRect tempFrame = self.frame; tempFrame.size.width = width; self.frame = tempFrame;}- (CGFloat)width;{ return self.frame.size.width;}//=================================- (void)setHeight:(CGFloat)height;{ CGRect tempFrame = self.frame; tempFrame.size.height = height; self.frame = tempFrame;}- (CGFloat)height;{ return self.frame.size.height;}//=================================- (void)setSize:(CGSize)size;{ CGRect tempFrame = self.frame; tempFrame.size = size; self.frame = tempFrame;}- (CGSize)size;{ return self.frame.size;}//=================================- (void)setCenterX:(CGFloat)x;{ CGPoint tempPoint = self.center; tempPoint.x = x; self.center = tempPoint;}- (CGFloat)centerX;{ return self.center.x;}//=================================- (void)setCenterY:(CGFloat)y;{ CGPoint tempPoint = self.center; tempPoint.y = y; self.center = tempPoint;}- (CGFloat)centerY;{ return self.center.y;}//=================================@end
In the. h file
#import <UIKit/UIKit.h>@interface UIView (MyFrameCategory)@property(nonatomic,assign) CGFloat x;@property(nonatomic,assign) CGFloat y;@property(nonatomic,assign) CGFloat width;@property(nonatomic,assign) CGFloat height;@property(nonatomic,assign) CGFloat centerX;@property(nonatomic,assign) CGFloat centerY;@property(nonatomic,assign) CGSize size;@end