UIView的一般操作 - iOS - UI基础知识总结1
来源:互联网 发布:mysql 开启慢日志 编辑:程序博客网 时间:2024/05/18 18:17
// UIView__________________________________
// 创建四个view__________________________________
// redView
UIView *redView = [[UIView alloc]initWithFrame:CGRectMake(50, 50, 200, 100)];
redView.backgroundColor = [UIColor redColor];
[containerView addSubview:redView];
[redView release];
// orangeView
UIView *orangeView = [[UIView alloc]initWithFrame:CGRectMake(80, 80, 200, 100)];
orangeView.backgroundColor = [UIColor orangeColor];
[containerView addSubview:orangeView];
[orangeView release];
// blueView
UIView *blueView = [[UIView alloc]initWithFrame:CGRectMake(110, 110, 200, 100)];
blueView.backgroundColor = [UIColor blueColor];
[containerView addSubview:blueView];
[blueView release];
// purpleView
UIView *purpleView = [[UIView alloc]initWithFrame:CGRectMake(140, 140, 200, 100)];
purpleView.backgroundColor = [UIColor purpleColor];
[containerView addSubview:purpleView];
[purpleView release];
// 设置view背景颜色_________________________________
((UIView *)[[containerView subviews]objectAtIndex:1]).backgroundColor = [UIColor whiteColor];
// 插入一个view__________________________________
UIView *grayView = [[UIView alloc]initWithFrame:CGRectMake(60, 100, 100, 100)];
grayView.backgroundColor = [UIColor grayColor];
// 在某个位置插入一个view
[containerView insertSubview:grayView atIndex:1];
[grayView release];
// 在某个view上面插入一个view
[containerView insertSubview:grayView aboveSubview:purpleView];
[grayView release];
// 在某个view下面插入一个view
[containerView insertSubview:grayView belowSubview:purpleView];
[grayView release];
// 管理视图层次__________________________________
// 把指定的子视图移到最前面
[containerView bringSubviewToFront:redView];
// 把指定的子视图移到最后面
[containerView sendSubviewToBack:orangeView];
// 交换两个字视图的位置
[containerView exchangeSubviewAtIndex:1 withSubviewAtIndex:2];
// 把某个子视图从父视图中移除
[redView removeFromSuperview];
// 隐藏某个view__________________________________
redView.hidden = YES;
// 获取本视图的所有子视图__________________________________
NSArray *subviews = [containerView subviews];
NSLog(@"subviews = %@",subviews);
// 获取本视图的父视图__________________________________
redView.superview.backgroundColor = [UIColor blackColor];
// 对一个view添加tag值(对一个view添加一个标记,一般要大于100)__________________________________
redView.tag = 111;
// 父视图根据tag值找到对应的子视图__________________________________
[containerView viewWithTag:111].backgroundColor = [UIColor grayColor];
// 设置view的透明度__________________________________
orangeView.alpha = 0.4;
// 设置view的拐角半径__________________________________
redView.layer.cornerRadius = 10;
// 创建四个view__________________________________
// redView
UIView *redView = [[UIView alloc]initWithFrame:CGRectMake(50, 50, 200, 100)];
redView.backgroundColor = [UIColor redColor];
[containerView addSubview:redView];
[redView release];
// orangeView
UIView *orangeView = [[UIView alloc]initWithFrame:CGRectMake(80, 80, 200, 100)];
orangeView.backgroundColor = [UIColor orangeColor];
[containerView addSubview:orangeView];
[orangeView release];
// blueView
UIView *blueView = [[UIView alloc]initWithFrame:CGRectMake(110, 110, 200, 100)];
blueView.backgroundColor = [UIColor blueColor];
[containerView addSubview:blueView];
[blueView release];
// purpleView
UIView *purpleView = [[UIView alloc]initWithFrame:CGRectMake(140, 140, 200, 100)];
purpleView.backgroundColor = [UIColor purpleColor];
[containerView addSubview:purpleView];
[purpleView release];
// 设置view背景颜色_________________________________
((UIView *)[[containerView subviews]objectAtIndex:1]).backgroundColor = [UIColor whiteColor];
// 插入一个view__________________________________
UIView *grayView = [[UIView alloc]initWithFrame:CGRectMake(60, 100, 100, 100)];
grayView.backgroundColor = [UIColor grayColor];
// 在某个位置插入一个view
[containerView insertSubview:grayView atIndex:1];
[grayView release];
// 在某个view上面插入一个view
[containerView insertSubview:grayView aboveSubview:purpleView];
[grayView release];
// 在某个view下面插入一个view
[containerView insertSubview:grayView belowSubview:purpleView];
[grayView release];
// 管理视图层次__________________________________
// 把指定的子视图移到最前面
[containerView bringSubviewToFront:redView];
// 把指定的子视图移到最后面
[containerView sendSubviewToBack:orangeView];
// 交换两个字视图的位置
[containerView exchangeSubviewAtIndex:1 withSubviewAtIndex:2];
// 把某个子视图从父视图中移除
[redView removeFromSuperview];
// 隐藏某个view__________________________________
redView.hidden = YES;
// 获取本视图的所有子视图__________________________________
NSArray *subviews = [containerView subviews];
NSLog(@"subviews = %@",subviews);
// 获取本视图的父视图__________________________________
redView.superview.backgroundColor = [UIColor blackColor];
// 对一个view添加tag值(对一个view添加一个标记,一般要大于100)__________________________________
redView.tag = 111;
// 父视图根据tag值找到对应的子视图__________________________________
[containerView viewWithTag:111].backgroundColor = [UIColor grayColor];
// 设置view的透明度__________________________________
orangeView.alpha = 0.4;
// 设置view的拐角半径__________________________________
redView.layer.cornerRadius = 10;
0 0
- UIView的一般操作 - iOS - UI基础知识总结1
- UI基础知识 -- UIView UILabel
- UIImagePickerController 的基本用法 - iOS - UI基础知识总结14
- iOS开发UI篇-UIView的生命周期
- IOS UI-UIView
- 2.IOS>UI>UIView
- UITextField - iOS - UI基础知识总结4
- UIButton - iOS - UI基础知识总结5
- UISegmentedControl - iOS - UI基础知识总结8
- UISlider - iOS - UI基础知识总结9
- UINavigationController - iOS - UI基础知识总结12
- iOS开发之UIView的一些总结
- ios 学习总结之UIView的动画
- iOS开发UI篇 -- UIView
- iOS-UI-01 UIWindow UIView
- IOS--UI--UIView文件解读
- IOS-UI-视图控件UIview
- iOS初学笔记UI--UIView
- JSTL 的 if else : 有 c:if 没有 else 的处理
- 华为OJ之中级篇Ⅰ
- libcurl教程(转)
- Android ANR错误排查
- sublime快捷键
- UIView的一般操作 - iOS - UI基础知识总结1
- ztree学习与使用
- Swift-可选类型(Optional)以及解包
- C++成员变量的初始化顺序问题
- 深入理解DIP、IoC、DI以及IoC容器
- Unity中批处理对Shader的影响
- Use of delimiter on Stored Procedure in MySQL
- https://leetcode.com/problems/gas-station/
- 链式栈的基本操作——LinkStack(C语言版)