iOS 基础-----关于UIView 的 frame 与 bounds
来源:互联网 发布:vip视频解析网站源码 编辑:程序博客网 时间:2024/06/05 09:58
首先,对于frame 大家都很熟悉,是当前view ,相对于其父视图view 的坐标,例如:
UIView *view1 = [[UIView alloc] initWithFrame:CGRectMake(10, 60, 300, 300)]; view1.backgroundColor = [UIColor redColor]; [self.view addSubview: view1];
view1 的坐标就是针对self.view 所设置的。其中view1 距 self.view 的左侧边缘是10px,距self.view 的顶部 60px。
现在我们设置view1 的bounds ,
view1.bounds = CGRectMake(-10, 60, 300, 300);
然后运行,你会发现view1的位置没有任何变化,这就对了,bounds是针对view1自身坐标,view1 的bounds 的x ,y 默认是其左上顶点(0,0);运行如图:
现在,我们在view1 上加view2,
UIView *view2 = [[UIView alloc] initWithFrame:CGRectMake(10, 40, 100, 100)]; view2.backgroundColor = [UIColor yellowColor]; [view1 addSubview: view2];运行如下图:
也就是说,对bounds 的设置 会对view 上的子视图的布局产生影响,不理解的同学,可以自己多试一试,然后就会印象深刻点。
- iOS 基础-----关于UIView 的 frame 与 bounds
- iOS 基础-----关于UIView 的 frame 与 bounds
- iOS 基础-----关于UIView 的 frame 与 bounds
- UIView的frame与bounds
- UIView的frame与bounds
- UIView的frame与bounds
- UIView frame与bounds的区别
- UIView的frame和bounds
- IOS bounds与Frame
- ios 中UIView bounds 和 frame 属性的区别
- iOS之详解UIView的frame、bounds和center属性
- iOS-UIView属性之frame和bounds的区别
- 视图UIView的frame、bounds与center属性
- 视图UIView的frame、bounds与center属性
- 视图UIView的frame、bounds与center属性
- 视图UIView的frame、bounds与center属性
- 视图UIView的frame、bounds与center属性
- 视图UIView的frame、bounds与center属性
- PowerDesigner 将code值赋给name列
- (copy)Asp.net中服务端控件事件是如何触发的
- 怎样运行地理处理工具 Geoprocessing & Geoprocessor & IGPProcess
- win2003远程终端服务激活
- HTTP中Get与Post的区别
- iOS 基础-----关于UIView 的 frame 与 bounds
- 为有数据的表加入id主健的方法
- ios --- block 内存管理 解决循环调用 学习
- Oracle编辑SQL语句(多次重复语句输入时简化)
- WritePrivateProfileString等读写.ini配置文件 .
- 软件项目开发流程(转)
- 撕裂牛仔的实穿八大法则
- 解决IIS 8.0 500.24错误
- 数论的开始[以Nyoj 458 小光棍数为例]