选择App会为我们创建一个单页应用

image.png
这里需注意我们的语言使用Swift 前期先把下面的checkbox先uncheck 我们暂时用不到

image.png
接下来就可以看到为我们自动创建的这几个文件
- AppDelegate: 处理 App 生命周期 和 Scene Session 生命周期
- SceneDelegate: 处理UI的生命周期
- ViewController: 控制视图
- Assets: 资源目录
- Main.storyboard: 故事板文件
- LaunchScreen.storyboard: 应用启动界面故事板文件
- info.plist: 属性文件

image.png
Storyboard模式实现
选中Main.storyboard可以看到一个白色面板选择加号新建一个label拖到画布中
同时也可以选择左侧机型来切换

image.png
在这里替换成Hello World 点击左侧运行 看下效果

image.png
Done
image.png
代码模式实现
如果不想使用storyboard实现 我们可以用纯代码方式实现
同样重新创建APP 这次我们用OC语言
创建好后删除storyboard文件
Main interface 中 Main清空

image.png
选择info.plist 删除storyboard Name

image.png
由于SceneDelegate负责UI 所以我们在 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中新增一个label 添加进去
- (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