- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// Override point for customization after application launch.
//创建window
self.window = [[UIWindow alloc ]init];
//让window和屏幕的宽高一样,位置也一样
_window.frame =[ UIScreen mainScreen].bounds;//bounds =(0,0,屏幕宽,屏幕高)
_window.backgroundColor = [UIColor yellowColor];
//上面两步相当于
//self.window = [[UIWindow alloc]initWithFrame:[UIScreen mainScreen].bounds];
//显示屏幕
[_window makeKeyAndVisible];
//创建BlueView试图
//开辟空间并初始化
UIView * blueView = [[UIView alloc]initWithFrame:CGRectMake(100, 100, 100, 100)];
//对视图进行设置
blueView.backgroundColor = [UIColor blueColor];
//将视图添加到window来显示
[_window addSubview:blueView];
//释放视图对象
UIView * redView = [[UIView alloc]initWithFrame:CGRectMake(100, 300, 100, 100)];
//对视图进行设置
redView.backgroundColor = [UIColor redColor];
//将试图添加到window来显示
[_window addSubview:redView];
//释放视图对象
UIView * blackView = [[UIView alloc]initWithFrame:CGRectMake(100, 200, 100, 100)];
blackView.backgroundColor = [ UIColor blackColor];
[_window addSubview:blackView];
//参照blueview(父视图)左上角的起点位置,
UIView * orangeView =[[UIView alloc]initWithFrame:CGRectMake(50, 50, 100, 100)];
orangeView.backgroundColor = [UIColor orangeColor];
[blueView addSubview:orangeView];
//修改中心点位置
//blackView.center = CGPointMake(200, 300);
CGPoint tempCenter = blackView.center;
tempCenter.x = 200;
tempCenter.y = 350;
blackView.center = tempCenter;
[_window release];
[blueView release];
[redView release];
[blackView release ];
[orangeView release];
#pragma mark----frame,center,bounds
//frame:可以改变视图的大小和位置,相对于父视图
//center:只能改变视图的位置
//bounds:能改变视图的大小,但是中心点不会改变,相对于自身。但是它会影响这个视图上所有子视图的布局(位置)。
#pragma mark-----添加视图
UIView * grayView =[[UIView alloc]initWithFrame:CGRectMake(50, 50, 100, 100)];
grayView.backgroundColor =[UIColor grayColor];
[_window insertSubview:grayView atIndex:0];
[grayView release];
//将grayview移到最前面(最上面)
[_window bringSubviewToFront:grayView];
//将redView从父视图上移除
//[redView removeFromSuperview];
//UIView的相关属性
//redView.hidden = YES;//设置视图是否隐藏
redView.alpha = 0.5;//设置透明度,默认1.0 ;
NSLog(@"%@",redView .superview);//获取父视图
NSLog(@"%@",redView.subviews);//获取某视图上的所有子视图
grayView.tag = 100;
UIView * v =[_window viewWithTag:100];
NSLog(@"%@",v);
#pragma mark----UILable
UILabel * label = [[UILabel alloc] initWithFrame:CGRectMake(100, 400, 200, 60)];
//设置文本内容(显示的内容)
label.text = @"Hello Baby! Can I make L with you!";
//背景颜色
label.backgroundColor = [UIColor cyanColor];
//文本字体
label.font = [UIFont fontWithName:@"Times New Roman" size:14];
NSLog(@"%@",[UIFont familyNames]);
//文本颜色
label.textColor = [UIColor redColor];
//设置对齐方式
label.textAlignment= 0 ;
//设置换行模式
label.lineBreakMode= NSLineBreakByWordWrapping ;
//设置行数
label.numberOfLines = 3;
//设置文本阴影
label.shadowColor =[ UIColor blackColor];
//设置阴影的偏移量
label.shadowOffset = CGSizeMake(20,20);
[_window addSubview:label];
[label release];
UIView及其子类
最新推荐文章于 2016-09-04 21:47:00 发布