UIView视图层次操作
2014-08-26 10:50
239 查看
//UIView //hiden removeFormSuperview release //看不见 会被销毁,将该对象从响应者链中删除, 简单的销毁对象 // 并且将view从屏幕上移除 //UIView层次 //view1是window的子视图 //view2是view1的子视图 UIView *view1 = [[UIView alloc] initWithFrame:CGRectMake(30, 30, 100, 100)]; view1.backgroundColor = [UIColor purpleColor]; //裁剪子视图,裁剪子视图超过父视图的区域 view1.clipsToBounds = YES; //隐藏视图,所有的子视图也会被隐藏 view1.hidden = YES; [self.window addSubview:view1]; UIView *view2 = [[UIView alloc] initWithFrame:CGRectMake(30, 30, 100, 100)]; view2.backgroundColor = [UIColor yellowColor]; [view1 addSubview:view2];//添加子视图 UIView *view3 = [[UIView alloc] initWithFrame:CGRectMake(90, 90, 100, 100)]; view3.backgroundColor = [UIColor greenColor]; [self.window addSubview:view3];//添加子视图 //[self.window addSubview:view3]; //最后一次生效 //视图层次操作 //删除view //[view3 removeFromSuperview]; //将该view从父视图中删除 //插入视图 UIView *view4 = [[UIView alloc] initWithFrame:CGRectMake(90, 90, 300, 50)]; view4.backgroundColor = [UIColor blueColor]; [self.window insertSubview:view4 atIndex:[self.window subviews].count]; //将view4添加到view3之下 //[self.window insertSubview:view4 belowSubview:view3]; //将view4添加到view3之上 //[self.window insertSubview:view4 aboveSubview:view3]; //交换 //[self.window exchangeSubviewAtIndex:0 withSubviewAtIndex:1]; //将view放到最底下 //[self.window sendSubviewToBack:view4]; //将view放到最顶上 [self.window bringSubviewToFront:view4]; //获取所有子视图,一个view可以有多个子视图 NSArray *subs = [self.window subviews]; NSLog(@"subs = %@", subs); //一个view只能有一个父视图 UIView *superView = [view3 superview]; NSLog(@"superView = %@", superView);
相关文章推荐
- UIWindow与视图UIView深层解析-链接地址 层次
- 打印UIView视图层次关系(转)
- UIView层次管理和视图切换
- iOS开发UIView的属性,父视图和子视图的层级操作,子视图的自适应模式,外加一个定时器
- UI06-UIView视图层次关系
- iOS 视图UIview属性介绍 以及视图层次方法
- 【iOS开发-14】UIView的属性,父视图和子视图的层级操作,子视图的自适应模式,外加一个定时器
- UIView回调方法(可以在添加子视图等,做一些额外操作)
- Xcode9学习笔记4 - UIView视图的层次关系
- UIView操作:插入添加置顶,判断一个视图是否为子视图view
- [转]UIView的属性,父视图和子视图的层级操作,子视图的自适应模式,外加一个定时器
- UIday01: UIView及其子类 UIView UILabel frame center bounds 管理视图层次 控制文本显示
- UI07 -UIView视图的基本操作
- 基于数据库(access)层次编码记录对TreeView的操作(实现自动编码,灵活控制编码规则和编码层次)
- SQL2K数据库开发十八之视图操作修改和重命名视图
- 视图操作girdview明细表detailsviw中放入dropdownlist
- Visual C# 2008+SQL Server 2005 数据库与网络开发-- 4.5 操作视图
- 基于数据库(access)层次编码记录对TreeView的操作(实现自动编码,灵活控制编码规则和编码层次)
- [网络问题,截图以后再传]本实验是设计性实验。目的在于使用关系数据库标准语言SQL,掌握视图和索引的操作。
- 孙鑫VC视频教程笔记之第五课“在视图上实现文本操作”