IOS开发之UI--创建一个手机屏幕大小的窗口


#import "AppDelegate.h"


@interface AppDelegate ()


@end


@implementation AppDelegate


//应用程序启动成功后调用

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

    // Override point for customization after application launch.

    //如果不在这个方法中创建界面,那么程序会自动加载main.storyboadrd来创建界面

    //也就是自动创建一个UIWindow

    

    //1.创建UIWindow对象

    _window = [[UIWindow alloc]init];

    //2.设置frame属性(默认xy0,宽和高也是0)是从UIView继承下来的

    //所有视图想要显示在界面上,必须设置它的位置(坐标是xy来确定的)

    //和大小(宽和高来确定的);

    //告诉系统当前这个视图是怎么显示的

    //ios中,坐标计算采用的ios坐标系(原点在左上角)


//    struct CGRect {

//        CGPoint origin;

//        CGSize size;

//    };


    

    //使用C语言的方式创建结构体变量

    //坐标

    CGPoint point = {0,0};

    //大小

    CGSize size = {375,667};

    //frame是由坐标和大小组成的

    CGRect rect = {point,size};

    //frame创建一个window

    [_window setFrame:rect];

    

    //3.设置背景颜色 - UIView的属性

    

    [_window setBackgroundColor:[UIColor yellowColor]];

    

    

    

    

    //4.window成为主窗口并且显示出来

    [_window makeKeyAndVisible];

    

    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


你可能感兴趣的:(UI创建一个窗口)