美文网首页
ios Hello World Xocde 12

ios Hello World Xocde 12

作者: 龚达耶 | 来源:发表于2021-03-31 15:58 被阅读0次

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


    image.png

    代码模式实现

    如果不想使用storyboard实现 我们可以用纯代码方式实现
    同样重新创建APP 这次我们用OC语言

    创建好后删除storyboard文件
    Main interface 中 Main清空


    image.pngimage.png

    选择info.plist 删除storyboard Name


    image.pngimage.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.pngimage.png

    相关文章

      网友评论

          本文标题:ios Hello World Xocde 12

          本文链接:https://www.haomeiwen.com/subject/pefahltx.html