选择App会为我们创建一个单页应用
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
网友评论