在UIView+Frame.h中:
#import <UIKit/UIKit.h>
@interface UIView (Frame)
@property (assign, nonatomic) CGFloat x;
@property (assign, nonatomic) CGFloat y;
@property (assign, nonatomic) CGFloat w;
@property (assign, nonatomic) CGFloat h;
@end
在UIView+Frame.m中:
#import "UIView+Frame.h"
@implementation UIView (Frame)
- (void)setX:(CGFloat)x
{
CGRect rect = self.frame;
rect.origin.x = x;
self.frame = rect;
}
- (CGFloat)x
{
return self.frame.origin.x;
}
- (void)setY:(CGFloat)y
{
CGRect rect = self.frame;
rect.origin.y = y;
self.frame = rect;
}
- (CGFloat)y
{
return self.frame.origin.y;
}
- (void)setW:(CGFloat)w
{
CGRect rect = self.frame;
rect.size.width = w;
self.frame = rect;
}
- (CGFloat)w
{
return self.frame.size.width;
}
- (void)setH:(CGFloat)h
{
CGRect rect = self.frame;
rect.size.height = h;
self.frame = rect;
}
- (CGFloat)h
{
return self.frame.size.height;
}
@end