读书人

IOS几个根本界面元素window(窗口)、

发布时间: 2012-06-29 15:48:46 作者: rapoo

IOS几个基本界面元素window(窗口)、视图(view)

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions{ self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];//系统帮你建画框 // Override point for customization after application launch. //自己测试一下 bounds与aplicationFrame的区别 CGRect bound = [[UIScreen mainScreen]bounds]; NSLog(@"boundwidth:%f boundheight:%f ",bound.size.width, bound.size.height); NSLog(@"boundx:%f boundy:%f ",bound.origin.x, bound.origin.y); CGRect appBound = [[UIScreen mainScreen]applicationFrame]; NSLog(@"appBoundwidth:%f appBoundheight:%f ",appBound.size.width, appBound.size.height); NSLog(@"appBoundx:%f appBoundy:%f ",appBound.origin.x, appBound.origin.y); //画第一块画布然涂成蓝色,大小是320 X 100 CGRect CGone = CGRectMake(0.0, 0.0, 320, 100);//画个矩形,初始化位置与大小 UIView *v_one = [[UIView alloc]initWithFrame:CGone];//初始化view v_one.backgroundColor = [UIColor blueColor];// 涂成蓝色 [self.window addSubview:v_one];//直接加到画框上 //第二块注意它的位置 CGRect CGtwo = CGRectMake(0.0, 100, 160, 100);//画个矩形、初始化位置与大小 UIView *v_two = [[UIView alloc]initWithFrame:CGtwo];//初始化view v_two.backgroundColor = [UIColor redColor];//涂成红色 [self.window addSubview:v_two];//叠加到画框 //第三块注意他的位置 CGRect CGthree = CGRectMake(160, 100, 160, 100);// UIView *v_three = [[UIView alloc]initWithFrame:CGthree];// v_three.backgroundColor = [UIColor greenColor];// [self.window addSubview:v_three];// //第四块注意它的位置 CGRect CGfour = CGRectMake(0.0, 260, 320, 200);// UIView *v_four = [[UIView alloc]initWithFrame:CGfour];// v_four.backgroundColor = [UIColor orangeColor];// [self.window addSubview:v_four];////第五块,计算一下它的位置,看看它的效果,你可以让试一下把这段代码移到第一快初始化的上面试试,会有意想不到的效果 CGRect CGfive = CGRectMake(100, 150, 160, 200); UIView *v_five = [[UIView alloc]initWithFrame:CGfive]; v_five.backgroundColor = [UIColor yellowColor]; [self.window addSubview:v_five]; self.window.backgroundColor = [UIColor grayColor];// [self.window makeKeyAndVisible];// return YES;}

?

转自:http://blog.csdn.net/iukey/article/details/7083165

读书人网 >操作系统

热点推荐