iOS 基础 第一节 UIview
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// Override point for customization after application launch.
//第一次运行时候加载
//每次运行只走一次, 系统自动监听
self.window = [[UIWindow alloc]initWithFrame:CGRectMake(0, 0, 320, 568)];
//背景颜色设置
[self.window setBackgroundColor:[UIColor grayColor]];
//设置主屏幕并显示
[self.window makeKeyAndVisible];
//创建UIView
UIView *aview = [[UIView alloc]initWithFrame:CGRectMake(0, 20, 100, 150)];
[aview setBackgroundColor:[UIColor orangeColor]];
[self.window addSubview:aview];
UIView *bview = [[UIView alloc]initWithFrame:CGRectMake(10, 15, 80, 100)];
[bview setBackgroundColor:[UIColor redColor ]];
[aview addSubview:bview];
UIView *cview = [[UIView alloc]initWithFrame:CGRectMake(20, 20, 50, 50)];
[cview setBackgroundColor:[UIColor greenColor]];
[aview addSubview:cview];
//法1.给属性赋值修改
cview.frame = CGRectMake(50, 0, 50, 50);
//法2.
// [cview setFrame:CGRectMake(50, 0, 50, 50)];
[aview release];
//[self.window release];
//获得试图的父试图
//强转(UIwindow)
UIWindow * fatherView = (UIWindow *)[aview superview];
NSLog(@"father = %@", fatherView);
//获得父试图的所有子试图
//返回数组
NSArray * arr = [aview subviews];
NSLog(@"subs = %@", arr);
//插入一个view
UIView *newView = [[UIView alloc]initWithFrame:CGRectMake(20, 30, 40, 40)];
[newView setBackgroundColor:[UIColor whiteColor]];
[aview insertSubview:newView aboveSubview:bview];
[newView release];
//放在b之上 但是数组位置在插入view数组位置之后,试图越在前,数组越在后
//管理试图层次
//把子试图中的newView放到最上面
[aview bringSubviewToFront:newView];
NSLog(@"%@", arr);
NSLog(@"%@", [aview subviews]);
// 把子试图中的newView放到最下面
[aview sendSubviewToBack:newView];
NSLog(@"%@", [aview subviews]);
//交换两个制定索引位置的子试图
[aview exchangeSubviewAtIndex:0 withSubviewAtIndex:2];
NSLog(@"%@", [aview subviews]);
//把receiver从父图上移除
//把newview 移除
// [newView removeFromSuperview];
// NSLog(@"%@", [aview subviews]);
//设置隐藏属性
// aview.hidden = YES;
[aview setHidden:NO];
//设置透明度 属性调用
//bview.alpha = 0.5;
[bview setAlpha:1];
//给视图标记
bview.tag =1;
//中心点 子视图相对与父视图
bview.center = CGPointMake(100, 100);
return YES;
}
郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。