ios ui第一课,创建第一个ui程序

这篇博客介绍了如何使用Objective-C创建一个简单的iOS应用。从选择Single View Application模板开始,设置语言为Objective-C,设备类型可选iPhone、Universal或iPad。接着,删除默认的ViewController文件,并在General设置中修改Main Interface。最后提到了AppDelegate是应用的真正入口,而非main.m文件。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

创建一个ui的项目:

创建的时候选择iOS->Application->Single View Application


选择:language 为objective-c ,以后如果是swift就选择swift,

device:可以先选择iPhone,还可以选择universal 或者是iPad。



0:删除3个文件ViewController.hViewController.mMain.storyboard


1:修改点击左边的蓝色按钮,然后选择general-》developer info-》main interface ,将这个main interface 晴空



appDelegate.h

//
//  AppDelegate.h
//  FirstViewUI
//
//  Created by 千雅爸爸 on 16/10/7.
//  Copyright © 2016年 kodulf. All rights reserved.
//

#import <UIKit/UIKit.h>
//launchscreen.storyboard 这些是可以直接使用,但是最好还是先手动的去做
//主要是了解逻辑
//就像android 中的ui 可以直接拖拽,但是最好手动的去做
//为了练习,我们将删除3个文件ViewController.h,ViewController.m,Main.storyboard
//注意是要选择move to trush,这样才能够彻底的删除掉
//这个时候一运行程序会崩溃掉,因为我们的
//修改点击左边的蓝色按钮,然后选择general-》develope info-》main interface ,将这个main interface 晴空

@interface AppDelegate : UIResponder <UIApplicationDelegate>

@property (strong, nonatomic) UIWindow *window;


@end

appDelegate.m

//
//  AppDelegate.m
//  FirstViewUI
//
//  Created by 千雅爸爸 on 16/10/7.
//  Copyright © 2016年 kodulf. All rights reserved.
//

#import "AppDelegate.h"

@interface AppDelegate ()

@end

@implementation AppDelegate

//应用程序启动以后完成那些初始化的工作
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    
    //self.window = [[UIWindow alloc]init];//此时还是漆黑一片
    //self.window = [[UIWindow alloc] initWithFrame:CGRectMake(0, 0, 100, 100)];
    //window 一般都是我们的底层视图,所以要充满屏幕
    self.window =[[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];//通过这个bounds 棒子来获取屏幕的大小
    
    [self.window setBackgroundColor:[UIColor yellowColor]];//设置为
    [self.window makeKeyAndVisible];//展示
    [self.window setRootViewController:[[UIViewController alloc]init]];
    
    
    // Override point for customization after application launch.
    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






注意:

main.m文件并不是入口,真正的入口就是appdelegate

//
//  main.m
//  FirstViewUI
//
//  Created by 千雅爸爸 on 16/10/7.
//  Copyright © 2016年 kodulf. All rights reserved.
//

#import <UIKit/UIKit.h>
#import "AppDelegate.h"

//launchscreen.storyboard 这些是可以直接使用,但是最好还是先手动的去做
//主要是了解逻辑
//就像android 中的ui 可以直接拖拽,但是最好手动的去做

//这个会转化到AppDelegate ,所以真正的入口就是appdelegate
int main(int argc, char * argv[]) {
    @autoreleasepool {
        return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class]));
    }
}







评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值