CGPoint point=CGPoint(x,y);  //表示位置

CGSize size=CGSzieMake(width,height);  //表示大小

CGRect rect=CGRectMake(x,y,width,height)

1.frame:

描述当前视图在其父视图中的位置和大小,用位置坐标和长度来表示:

sample:

UIButton *button3=[[[UIButtonalloc]initWithFrame:CGRectMake(120,120,100,100)]autorelease];

button3.backgroundColor=[UIColorgreenColor];

[self.view addSubview:button3];

NSLog(@"the result is %f,%f,%f,%f",button3.frame.size.height,button3.frame.size.width,button3.frame.origin.x,button3.frame.origin.y);

结果:

the result is 100.000000,100.000000,120.000000,120.000000

2. bounds  property

描述当前视图在其自身坐标系统中的位置和大小。

iphone中坐标系统的建立,最左上角是原点(0,0),向右为x轴递增,想下为y轴递减。

ios采用CGPoint来表示点在坐标系上X、Y位置。我们可以通过CGPointMake(x,y)来创建一个坐标点:CGPoint point = CGPointMake(80,40)

同时,ios采用CGSize来表示视图的宽度和高度,即视图的大小。我们可以通过CGSizeMake(width,height)来创建一个矩形的大小,如CGSize size = CGSizeMake(144,72)将创建一个宽度为144,高度为72的矩形大小。

而CGRect则是结合了CGPoint和CGSize,用来表示矩形的位置和大小。它的origin表示矩形右上角所在位置(CGPoint),size表示矩形的大小(CGSize)。

sample:

  UIButton *button3=[[[UIButton alloc] initWithFrame:CGRectMake(120, 120, 100, 100)] autorelease];
button3.backgroundColor=[UIColor greenColor];
[self.view addSubview:button3];
NSLog(@"the result is %f,%f,%f,%f",button3.frame.size.height,button3.frame.size.width,button3.frame.origin.x,button3.frame.origin.y); NSLog(@"the result is %f,%f,%f,%f",button3.bounds.origin.x,button3.bounds.origin.y,button3.bounds.size.height,button3.bounds.size.width);
}

3.center  property

描述当前视图的中心点在其父视图中的位置。

sample如下所示:

    UIButton *button3=[[[UIButton alloc] initWithFrame:CGRectMake(120, 120, 100, 100)] autorelease];
button3.backgroundColor=[UIColor greenColor];
[self.view addSubview:button3];
NSLog(@"the result is %f,%f",button3.center.x,button3.center.y);

result is:

the result is 170.000000,170.000000

4.frame.bounds 和center的区别和联系

这两个属性都是用来描述视图的大小(CGSize)和位置(CGPoint)的,两者都用CGRect表示。不同的是,frame描述的是在其父视图中的CGRect,而bounds描述的是在其自身视图中的CGRect,

center属性则用CGPoint表示矩形中心点在其父视图中的位置,frame、bounds和center三个属性是相互关联、相互影响的,其中一个属性发生变化,其他属性也会跟着变化。

frame.bounds和center的更多相关文章

  1. UIView frame, bounds and center

    http://stackoverflow.com/questions/5361369/uiview-frame-bounds-and-center Since the question I asked ...

  2. iOS--------坐标系统(UIView的frame、bounds跟center属性)

    1.概要翻开ios官方开发文档,赫然发现上面对这三个属性的解释如下: frame:描述当前视图在其父视图中的位置和大小. bounds:描述当前视图在其自身坐标系统中的位置和大小. center:描述 ...

  3. iOS 中的frame,bounds,center,transform关联

    这里有一篇好文章 http://www.winddisk.com/2012/06/07/transform/ 先看几个知识点,UIView 的frame,bounds,center,transform ...

  4. 《View Programming Guide for iOS》之frame、bounds和center之间的关系

    The frame property contains the frame rectangle, which specifies the size and location of the view i ...

  5. iOS开发——使用OC篇&frame,bounds,center,position,anchorPoint总结

    frame,bounds,center,position,anchorPoint总结 图层的 position 属性是一个 CGPoint 的值,它指定图层相当于它父图层的位置, 该值基于父图层的坐标 ...

  6. 初见IOS的UI之:UI控件的属性frame bounds center 和transform

    这些属性,内部都是结构体:CGRect CGPoint CGFloat 背景知识:所有的控件都是view的子类,屏幕就是一个大的view:每个view都有个viewController,它是view的 ...

  7. ios开发之UIView的frame、bounds跟center属性的区别(附图)

    博文暂时想到什么写什么,不顺理成章,不顺章成篇. 先看几个概念 坐标点Poit:向右侧为X轴正方向的值x,原点下侧为Y轴正方向的值y 大小Size:由宽度width和高度height构成,表示一个矩形 ...

  8. UIView 中 frame, bounds, center 属性的关系

    最近一直在学 iOS 开发,所以专门创建了这样一个类别,将自己学习中的一些问题整理,记录下来.由于自己是初学者,所以所写的文章非常基础,写这个类别一是为了给自己留下存 档,二是为了给和我有同样问题的初 ...

  9. 详解UIView的frame、bounds和center属性

    From: http://ios.wpjam.com/2011/08/29/uiview-frame-bounds-center/ 1.概要 翻开ios官方开发文档,赫然发现上面对这三个属性的解释如下 ...

随机推荐

  1. python读写xml

    来自http://blog.csdn.net/liuyuehui110/article/details/7287897 备份防止链接失效 一.XML的读取. 在 NewEdit 中有代码片段的功能,代 ...

  2. 不直接访问远程的数据库,而是通过中间件(专业DBA的博客)

    建议不直接访问远程的数据库,而是通过中间件. 或者找到好的加密方式.http://blog.csdn.net/sqlserverdiscovery/article/details/8068318 在S ...

  3. ASP.NET MVC 5 学习教程:添加控制器

    原文 ASP.NET MVC 5 学习教程:添加控制器 起飞网 ASP.NET MVC 5 学习教程目录: 添加控制器 添加视图 修改视图和布局页 控制器传递数据给视图 添加模型 创建连接字符串 通过 ...

  4. include与jsp:include区别

    jsp 中include有两种形式,分别是 <%@ include file=” ”%> <jsp:include page=” ” flush=”true”/> 前者是指令元 ...

  5. HDU SPFA算法 Invitation Cards

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1535 分析: 题意:求1点到其它点的最短距离之和+其它点到1点的最短距离之和 前面一部分直接用SPFA ...

  6. Actor::updateMassFromShapes

    unity报错Actor::updateMassFromShapes: Compute mesh inertia tensor failed for one of the actor's mesh s ...

  7. UVA - 10057 A mid-summer night&#39;s dream.

    偶数时,中位数之间的数都是能够的(包含中位数) 奇数时,一定是中位数 推导请找初中老师 #include<iostream> #include<cstdio> #include ...

  8. Ganglia 权威指南-安装Ganglia过程

    转自于:http://blog.csdn.net/xxd851116/article/details/21527055 http://www.dataguru.cn/article-3816-1.ht ...

  9. Python 第八篇:异常处理、Socket语法、SocketServer实现多并发、进程和线程、线程锁、GIL、Event、信号量、进程间通讯

    本节内容: 异常处理.Socket语法.SocketServer实现多并发.进程和线程.线程锁.GIL.Event.信号量.进程间通讯.生产者消费者模型.队列Queue.multiprocess实例 ...

  10. 《音乐商店》第4集:自动生成StoreManager控制器

    一.自动生成StoreManager控制器 二.查看 StoreManager 控制器的代码 现在,Store Manager 控制器中已经包含了一定数量的代码,我们从头到尾重新过一下. 1.访问数据 ...