点击创建UIView的分类category,这里命名为 PLExtension(为了和下面对应)
view分类.h文件
#import <UIKit/UIKit.h> @interface UIView (PLExtension) @property (nonatomic, assign) CGFloat WL_width; @property (nonatomic, assign) CGFloat WL_height; @property (nonatomic, assign) CGFloat WL_x; @property (nonatomic, assign) CGFloat WL_y; @property (nonatomic, assign) CGFloat WL_centerX; @property (nonatomic, assign) CGFloat WL_centerY; @property (nonatomic, assign) CGFloat WL_right; @property (nonatomic, assign) CGFloat WL_bottom; @end
.m文件
#import "UIView+PLExtension.h"
@implementation UIView (WLExtension)
- (CGFloat)WL_width
{
return self.frame.size.width;
}
- (CGFloat)WL_height
{
return self.frame.size.height;
}
- (void)setWL_width:(CGFloat)WL_width
{
CGRect frame = self.frame;
frame.size.width = WL_width;
self.frame = frame;
}
- (void)setWL_height:(CGFloat)WL_height
{
CGRect frame = self.frame;
frame.size.height = WL_height;
self.frame = frame;
}
- (CGFloat)WL_x
{
return self.frame.origin.x;
}
- (void)setWL_x:(CGFloat)WL_x
{
CGRect frame = self.frame;
frame.origin.x = WL_x;
self.frame = frame;
}
- (CGFloat)WL_y
{
return self.frame.origin.y;
}
- (void)setWL_y:(CGFloat)WL_y
{
CGRect frame = self.frame;
frame.origin.y = WL_y;
self.frame = frame;
}
- (CGFloat)WL_centerX
{
return self.center.x;
}
- (void)setWL_centerX:(CGFloat)WL_centerX
{
CGPoint center = self.center;
center.x = WL_centerX;
self.center = center;
}
- (CGFloat)WL_centerY
{
return self.center.y;
}
- (void)setWL_centerY:(CGFloat)WL_centerY
{
CGPoint center = self.center;
center.y = WL_centerY;
self.center = center;
}
- (CGFloat)WL_right
{
// return self.WL_x + self.WL_width;
return CGRectGetMaxX(self.frame);
}
- (CGFloat)WL_bottom
{
// return self.WL_y + self.WL_height;
return CGRectGetMaxY(self.frame);
}
- (void)setWL_right:(CGFloat)WL_right
{
self.WL_x = WL_right - self.WL_width;
}
- (void)setWL_bottom:(CGFloat)WL_bottom
{
self.WL_y = WL_bottom - self.WL_height;
}
@end
原文:http://www.cnblogs.com/peaker-wu/p/5689963.html