選擇App會(huì)為我們創(chuàng)建一個(gè)單頁(yè)應(yīng)用

image.png
這里需注意我們的語(yǔ)言使用Swift 前期先把下面的checkbox先uncheck 我們暫時(shí)用不到

image.png
接下來(lái)就可以看到為我們自動(dòng)創(chuàng)建的這幾個(gè)文件
- AppDelegate: 處理 App 生命周期 和 Scene Session 生命周期
- SceneDelegate: 處理UI的生命周期
- ViewController: 控制視圖
- Assets: 資源目錄
- Main.storyboard: 故事板文件
- LaunchScreen.storyboard: 應(yīng)用啟動(dòng)界面故事板文件
- info.plist: 屬性文件

image.png
Storyboard模式實(shí)現(xiàn)
選中Main.storyboard可以看到一個(gè)白色面板選擇加號(hào)新建一個(gè)label拖到畫(huà)布中
同時(shí)也可以選擇左側(cè)機(jī)型來(lái)切換

image.png
在這里替換成Hello World 點(diǎn)擊左側(cè)運(yùn)行 看下效果

image.png
Done
image.png
代碼模式實(shí)現(xiàn)
如果不想使用storyboard實(shí)現(xiàn) 我們可以用純代碼方式實(shí)現(xiàn)
同樣重新創(chuàng)建APP 這次我們用OC語(yǔ)言
創(chuàng)建好后刪除storyboard文件
Main interface 中 Main清空

image.png
選擇info.plist 刪除storyboard Name

image.png
由于SceneDelegate負(fù)責(zé)UI 所以我們?cè)?SceneDelegate.m新增
#import "ViewController.h"
- (void)scene:(UIScene *)scene willConnectToSession:(UISceneSession *)session options:(UISceneConnectionOptions *)connectionOptions {
UIWindowScene *windowScene = (UIWindowScene *)scene;
self.window = [[UIWindow alloc] initWithWindowScene:windowScene];
self.window.frame = windowScene.coordinateSpace.bounds;
self.window.backgroundColor = [UIColor whiteColor];
self.window.rootViewController = [ViewController new];
[self.window makeKeyAndVisible];
}
在ViewController.m中新增一個(gè)label 添加進(jìn)去
- (void)viewDidLoad {
[super viewDidLoad];
CGRect screen = [[UIScreen mainScreen] bounds];
CGFloat labelWidth = 90;
CGFloat labelHeight = 20;
CGFloat labelTopView = 150;
CGRect frame = CGRectMake((screen.size.width - labelWidth)/2, labelTopView, labelWidth, labelHeight);
UILabel* label = [[UILabel alloc] initWithFrame: frame];
label.text = @"Hi DDW";
label.textAlignment = NSTextAlignmentCenter;
[self.view addSubview:label];
// Do any additional setup after loading the view.
}
Done

image.png