UI 创建见View视图

来源:互联网 发布:51单片机蜂鸣器电路图 编辑:程序博客网 时间:2024/05/14 08:00

#import "TestDicAppDelegate.h"


@implementation TestDicAppDelegate


- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions

{

    //产生一个window对象,使它和屏幕的大小一样。

    self.window = [[UIWindowalloc] initWithFrame:[[UIScreenmainScreen] bounds]];

    // Override point for customization after application launch.

    self.window.backgroundColor = [UIColorblackColor];

    // window对象 设置为主window,并且可见。

    [self.windowmakeKeyAndVisible];

    

    

    // 1.建立一个UIView对象:

    // 2.UIView通过CGRect结构体确定位置大小。

    UIView *view9 = [[UIViewalloc] initWithFrame:(CGRectMake(150,10, 200, 440))];

    [view9 setBackgroundColor:[UIColordarkGrayColor]];

    [self.windowaddSubview:view9];

    

    UIView *view8 = [[UIViewalloc] initWithFrame:(CGRectMake(130,20, 190, 405))];

    [view8 setBackgroundColor:[UIColororangeColor]];

    view8.alpha = 0.9//透明度

    view8.hidden = NO//隐藏

    

    view8.tag =10000//设置viewtag值(作用:方便父视图快速定位子视图)

    

    [self.windowaddSubview:view8];

    NSLog(@"%@", view8.superview);

    

    // 通过tag寻找子视图

//    UIView *viewTemp = [self.window viewWithTag:10000];

    

    

    UIView *view7 = [[UIViewalloc] initWithFrame:(CGRectMake(110,40, 180, 355))];

    [view7 setBackgroundColor:[UIColorpurpleColor]];

    [self.windowaddSubview:view7];

    

    UIView *view6 = [[UIViewalloc] initWithFrame:(CGRectMake(90,60, 170, 305))];

    [view6 setBackgroundColor:[UIColorbrownColor]];

    [self.windowaddSubview:view6];

    

    UIView *view3 = [[UIViewalloc] initWithFrame:(CGRectMake(70,80, 160, 255))];

    [view3 setBackgroundColor:[UIColorblueColor]];

    [self.windowaddSubview:view3];

    

    UIView *view = [[UIViewalloc] initWithFrame:CGRectMake(50,100, 150, 205)];

    [view setBackgroundColor:[UIColoryellowColor]];

    

    // 3.view对象添加到 window

    [self.windowaddSubview:view];

    

    

    UIView *view1 = [[UIViewalloc] initWithFrame:(CGRectMake(30,120, 140, 155))];

    [view1 setBackgroundColor:[UIColorgreenColor]];

    [self.windowaddSubview:view1];

    

    UIView *view2 = [[UIViewalloc] initWithFrame:(CGRectMake(10,140, 130, 105))];

    [view2 setBackgroundColor:[UIColorredColor]];

    [self.windowaddSubview:view2];

    

    UIView *view4 = [[UIViewalloc] initWithFrame:(CGRectMake(-10,160, 120, 55))];

    [view4 setBackgroundColor:[UIColorcyanColor]];

    [self.windowaddSubview:view4];

    

    UIView *view5 = [[UIViewalloc] initWithFrame:(CGRectMake(20,180, 70, 15))];

    [view5 setBackgroundColor:[UIColormagentaColor]];

    view5.alpha = 0.5;

    [self.windowaddSubview:view5];

    

    // 改变中心点

//    view3.center = CGPointMake(0, 0);

    

    // 4.内存管理(释放)

    [view release];

    return YES;

}


- (void)applicationWillResignActive:(UIApplication *)application

{

    // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.

    // Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.

}


- (void)applicationDidEnterBackground:(UIApplication *)application

{

    // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later. 

    // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.

}


- (void)applicationWillEnterForeground:(UIApplication *)application

{

    // Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background.

}


- (void)applicationDidBecomeActive:(UIApplication *)application

{

    // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.

}


- (void)applicationWillTerminate:(UIApplication *)application

{

    // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.

}


@end


0 0
原创粉丝点击