// 在ARC下可以重写dealloc方法 但是不能使用[super dealloc]
- (void)dealloc
{
[_window release];
[super dealloc];
}
/*
- (void)test
{
// 取出tag值为100的view,修改其背景颜色为红色
UIView *view = [self.window viewWithTag:100];
view.backgroundColor = [UIColor redColor];
}
*/
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
/*
Window *window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
self.window = window;
[window release];
*/
// 1.创建一个与屏幕等大的window
self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]]autorelease];
// Override point for customization after application launch.
// 2.设置window的背景颜色
self.window.backgroundColor = [UIColor blackColor];
// 3.使用当前的window成为主窗口并且可见
[self.window makeKeyAndVisible];
/*
// 1.按照课件上的代码创建一个UIView对象
// 1>创建UIView
// 1.初始化方法
// 2.便利构造器
UIView *blueView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, 100, 100)];
// 2>设置UIView相关属性
blueView.backgroundColor = [UIColor blueColor];
// frame center是UIView的属性 frame和center在修改的时候 影响的是自身在父视图上的位置 是相对于父视图而言的
// 每一个View都有自身的一套坐标系
// blueView.center = CGPointMake(120, 120);
// blueView.frame = CGRectMake(30, 30, 80, 60);
// 打印blueView对应的bounds属性
// NSLog(@"%f,%f,%f,%f",blueView.bounds.origin.x,blueView.bounds.origin.y,blueView.bounds.size.width,blueView.bounds.size.height);
NSLog(@"%@",NSStringFromCGRect(blueView.bounds));
// blueView.bounds = CGRectMake(10, 0, 100, 100);
// 1)blueView 在父视图上得位置有没有发生变化 ==>没有发生变化
// 2)修改了一个视图的bounds之后 会对什么产生影响 ==>
// 1.如果只是修改了bounds的origin 会对该视图上的子视图产生影响
// 2.如果修改了bounds的size 会对franme产生影响 但是center不会改变
// 3>将其添加到父视图
[self.window addSubview:blueView];
NSLog(@"%@",self.window.subviews);
*/
/*
UIView *yellowView = [[UIView alloc]initWithFrame:CGRectMake(100, 100, 50, 50)];
yellowView.backgroundColor = [UIColor yellowColor];
[self.window addSubview:yellowView];
[yellowView release];
UIView *greenView = [[UIView alloc]initWithFrame:CGRectMake(150, 150, 50, 50)];
greenView.backgroundColor = [UIColor greenColor];
[self.window addSubview:greenView];
[greenView release];
CGRect test = CGRectMake(100, 150, 50, 50);
UIView *redView = [[UIView alloc]initWithFrame:test];
redView.backgroundColor = [UIColor redColor];
[self.window addSubview:redView];
[redView release];
*/
/*
// 2.创建一个UIView对象 对象的Frame为(100,100,200,250) 颜色为黄色,添加到window上
// 1>创建UIView
// 1.初始化方法
// 2.便利构造器
UIView *yellowView = [[UIView alloc]initWithFrame:CGRectMake(100, 100, 200, 200)];
// 2>设置UIView相关属性
yellowView.backgroundColor = [UIColor yellowColor];
// 练习: 1.修改yellowView的bounds为CGRectMake(10,0,200,250)
// 2.把blueView添加到yellowView上面
// 3.看看会产生什么样的影响 思考一下为什么会产生这样的影响
yellowView.bounds = CGRectMake(30, 0, 200, 200);
// 3>将其添加到父视图
[self.window addSubview:yellowView];
yellowView.alpha = 1;
UIView *greenView = [[UIView alloc]initWithFrame:CGRectMake(100, 100, 100, 100)];
greenView.backgroundColor = [UIColor greenColor];
// greenView.bounds = CGRectMake(10, 0, 100, 100);
[yellowView addSubview:greenView];
greenView.alpha = 0.5;
greenView.tag = 100;
[self.window insertSubview:yellowView atIndex:3];
NSLog(@"%@",self.window.subviews);
[self test];
// 4>释放
[blueView release];
[yellowView release];
[greenView release];
UIView *containView = [[UIView alloc]initWithFrame:CGRectMake(20, 20, 250, 180)];
containView.backgroundColor = [UIColor lightGrayColor];
[self.window addSubview:containView];
containView.center = CGPointMake(190, 280);
UIView *redView1 = [[UIView alloc]initWithFrame:CGRectMake(30, 30, 60, 30)];
redView1.backgroundColor = [UIColor redColor];
[containView addSubview:redView1];
UIView *redView2 = [[UIView alloc]initWithFrame:CGRectMake(30, 70, 60, 30)];
redView2.backgroundColor = [UIColor redColor];
[containView addSubview:redView2];
UIView *blueView1 =[[UIView alloc]initWithFrame:CGRectMake(110, 30, 110, 30)];
blueView1.backgroundColor = [UIColor blueColor];
[containView addSubview:blueView1];
UIView *blueView2 =[[UIView alloc]initWithFrame:CGRectMake(110, 70, 110, 30)];
blueView2.backgroundColor = [UIColor blueColor];
[containView addSubview:blueView2];
UIView *greenView1 =[[UIView alloc]initWithFrame:CGRectMake(30, 120, 50, 30)];
greenView1.backgroundColor = [UIColor greenColor];
[containView addSubview:greenView1];
UIView *greenView2 =[[UIView alloc]initWithFrame:CGRectMake(100, 120, 50, 30)];
greenView2.backgroundColor = [UIColor greenColor];
[containView addSubview:greenView2];
UIView *greenView3 =[[UIView alloc]initWithFrame:CGRectMake(170, 120, 50, 30)];
greenView3.backgroundColor = [UIColor greenColor];
[containView addSubview:greenView3];
[containView release];
[greenView3 release];
[greenView2 release];
[greenView1 release];
[blueView2 release];
[blueView1 release];
[redView2 release];
[redView1 release];
*/
UIView *containView = [[UIView alloc]initWithFrame:CGRectMake(20, 20, 250, 180)];
containView.backgroundColor = [UIColor lightGrayColor];
[self.window addSubview:containView];
containView.center = CGPointMake(190, 280);
[containView release];
/**
* UILabel:显示文本的控件 任何控件的创建都是分为4步
*/
// 1.创建对象
UILabel *label = [[UILabel alloc]initWithFrame:CGRectMake(0, 0, 300, 150)];
// 2.设置相关属性
label.backgroundColor = [UIColor whiteColor];
label.text = @"nozuonodie";
label.textColor = [UIColor purpleColor];
label.textAlignment = NSTextAlignmentCenter;
label.lineBreakMode = NSLineBreakByCharWrapping;
label.numberOfLines = 3;
label.shadowColor = [UIColor blackColor];
label.shadowOffset = CGSizeMake(2, 1);
// 3.添加到父视图上
[containView addSubview:label];
// 4.释放
[label release];
// 字体 字体集
// 黑体 黑体加粗 黑体倾斜
// 1.获取所有的字体集
NSArray *arr = [UIFont familyNames];
NSLog(@"%@",arr);
// 2.获得字体集里面对应的字体
NSArray *fontArr = [UIFont fontNamesForFamilyName:@"Lao Sangam MN"];
NSLog(@"%@",fontArr);
label.font = [UIFont fontWithName:@"LaoSangamMN" size:30];
label.font = [UIFont systemFontOfSize:25];
return YES;
}
UI -UIView和UILabel控件
最新推荐文章于 2016-04-05 15:19:40 发布