标签:
//1.创建window
self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];
// Override point for customization after application launch.
//2.设置window的属性(例如:背景颜色)
self.window.backgroundColor = [UIColor whiteColor];
//3.设置window为主窗口,并显示
[self.window makeKeyAndVisible];
/*
//步骤1.开辟内存,并初始化(坐标和尺寸)
UIView *yelloView = [[UIView alloc] initWithFrame:CGRectMake(50, 50, 100, 100)];
//步骤2.设置视图的属性
[yelloView setBackgroundColor:[UIColor yellowColor]];
//步骤3.添加到window上
[self.window addSubview:yelloView];
//步骤4.释放内存
[yelloView release];
//(50, 200, 100, 100) 蓝色
UIView *blueView = [[UIView alloc] initWithFrame:CGRectMake(50, 200, 100, 100)];
//背景颜色默认是透明的 (cleanColor)
blueView.backgroundColor = [UIColor blueColor];
[self.window addSubview:blueView];//添加子视图
[blueView release];
//移除子视图
// [blueView removeFromSuperview];
//frame:是父视图的坐标系
//改变父视图的位置,子视图也跟着移动
UIView *greenView = [[UIView alloc] initWithFrame:CGRectMake(20, 30, 50, 50)];
greenView.backgroundColor = [UIColor greenColor];
[blueView addSubview:greenView];
[greenView release];
blueView.frame = CGRectMake(100, 250, 100, 100);
//center :基于父视图的坐标系
NSLog(@"%@", NSStringFromCGPoint(yelloView.center));
//center.x = frame.origin.x + frame.size.width / 2;
//center.y = frame.origin.y + frame.size.height / 2;
// bounds:基于自身的坐标系
NSLog(@"%@", NSStringFromCGRect(yelloView.bounds));
//frame,center,bounds
//frame,bounds:CGRect
//center:CGPoint
//改变frame,影响center和bounds
//改变center,bounds不变,影响frame
//改变bounds,center不变,影响frame
NSLog(@"改变前");
NSLog(@"%@",NSStringFromCGRect(yelloView.frame));
NSLog(@"%@", NSStringFromCGPoint(yelloView.center));
NSLog(@"%@", NSStringFromCGRect(yelloView.bounds));
yelloView.frame = CGRectMake(100, 100, 100, 100);
NSLog(@"改变后");
NSLog(@"%@",NSStringFromCGRect(yelloView.frame));
NSLog(@"%@", NSStringFromCGPoint(yelloView.center));
NSLog(@"%@", NSStringFromCGRect(yelloView.bounds));
// hidden 显隐性,默认为NO
//YES 代表隐藏, 隐藏会影响子视图
cView.hidden = YES;
//不透明度 alpha.默认值是1.0
//值越小,越透明,影响子视图
aView.alpha = 0.5;
aView.backgroundColor = [UIColor colorWithRed:1 green:1 blue:0 alpha:0.5];//仅改变该视图的alpha的透明度
// aView.subviews
// aView.superview
//tag为视图添加整型标签,父视图可以通过标签,找到子视图
//一般tag要大于100,避免和系统相同,并且tag要做到不重复(同一个父视图内)
UIView *findView = [_window viewWithTag:1000];
//__function__打印的的是函数的名字 __line__函数所在的行数
标签:
原文地址:http://www.cnblogs.com/tian-sun/p/4309624.html