1.先创建UIView的类目,扩展UIview的功能。
在UIView+WLFrame.h文件中
#define kScreenWidth [UIScreen mainScreen].bounds.size.width
#define kScreenHeight [UIScreen mainScreen].bounds.size.height
高度
@property (nonatomic,assign) CGFloat height;
宽度
@property (nonatomic,assign) CGFloat width;
Y
@property (nonatomic,assign) CGFloat top;
X
@property (nonatomic,assign) CGFloat left;
Y + Height
@property (nonatomic,assign) CGFloat bottom;
X + width
@property (nonatomic,assign) CGFloat right;
在UIView+WLFrame.m文件中
返回高度
-(CGFloat)height
{
return self.frame.size.height;
}
设置高度
-(void)setHeight:(CGFloat)newheight
{
结构体的点语法 没有set get方法
不能直接进行赋值
正能通过 结构体的整个赋值
虽然都是点 但是意思不一样
以后结构就这么赋值
1.用一个变量接收结构体
2.修改这个新结构体变量的某一个值
3.重新赋值新的结构体
CGRect newframe = self.frame;
newframe.size.height = newheight;
self.frame = newframe;
}
返回宽度
-(CGFloat)width
{
return self.frame.size.width;
}
设置宽度
-(void)setWidth:(CGFloat)newwidth
{
CGRect newframe = self.frame;
newframe.size.width = newwidth;
self.frame = newframe;
}
返回Y
-(CGFloat)top
{
return self.frame.origin.y;
}
-(void)setTop:(CGFloat)newtop
{
CGRect newframe = self.frame;
newframe.origin.y = newtop;
self.frame = newframe;
}
返回X
-(CGFloat)left
{
return self.frame.origin.x;
}
设置X
-(void)setLeft:(CGFloat) newleft
{
CGRect newframe = self.frame;
newframe.origin.x = newleft;
self.frame = newframe;
}
返回Y + Height
-(CGFloat)bottom
{
return self.frame.origin.y + self.frame.size.height;
}
返回X + width
-(CGFloat)right
{
return self.frame.origin.x + self.frame.size.width;
}
2.把类目添加到全局
创建一个PrefixHeader.pch
在全局里引入UIView+WLFrame.h文件
#import “UIView+WLFrame.h”
在工程设置的设置里快速查找pref
选中Apple LLVM 6.1-Language下的Prefix Header 。。然后填写路径$(SRCROOT)/工程名/PrefixHeader.pch 回车