14.在全局中扩展UIVew的功能

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 回车

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值