14.在全局中扩展UIVew的功能
2015-11-16 19:33
525 查看
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 回车
相关文章推荐
- UI第五天:设计模式、⼿势识别器
- UIControl IOS控件编程 及UITextField的讲解
- UI设计中我们需要了解的知识
- Android-UI布局---onLayout、layout方法
- Educational Codeforces Round 1 B. Queries on a String
- [POJ 2778] DNA Sequence (AC自动机+DP+矩阵加速)
- [LeetCode] Range Sum Query - Immutable & Range Sum Query 2D - Immutable
- 《iOS Human Interface Guidelines》——Terminology and Wording
- 解决ntp的错误 no server suitable for synchronization found
- LeetCode -- Longest Increasing Subsequence
- UI:一个IOS工程的标准框架
- A sequence of numbers
- Rejected request from RFC1918 IP to public server address
- UITableViewCell自定义
- IOS 学习 开发 自定义 UINavigationController 导航
- vim中的quickfix window
- easyui datebox 只选择年月
- UITableViewCell不可以选中
- iOS开发UI篇—CAlayer(自定义layer)
- 不让activity显示UI的办法