iOS纯代码UI

2022-02-06  本文已影响0人  没脑子的程序员

1.删除main.storyboard文件

2.TARGETS->工程名字->General->Deployment Info里将Main interface里的内容删除 删除Main interface.png
3.Xcode11之后,由于SceneDelegate接管了AppDelegate的部分功能,需要删除info.plist中scene中对应的storyboard Name,如果不是Xcode之后创建的项目不需要这个操作
删除info.plist中的storyboard Name

接下来就可以在AppDelegate中指定自己的window作为启动的首页了

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    // Override point for customization after application launch.
    
    BOOL isGreaterThan13 = @available(iOS 13.0, *);
    if (!isGreaterThan13)
    {
        self.window = [[UIWindow alloc]initWithFrame:[[UIScreen mainScreen] bounds]];
        ViewController *controller = [[ViewController alloc]init];
        UINavigationController *nav = [[UINavigationController alloc]initWithRootViewController:controller];

        self.window.rootViewController = nav;
        [self.window makeKeyAndVisible];
    }
    
    return YES;
}

如果是iOS 13以上的,需要在SceneDelegate中也进行设置

- (void)scene:(UIScene *)scene willConnectToSession:(UISceneSession *)session options:(UISceneConnectionOptions *)connectionOptions {
    // Use this method to optionally configure and attach the UIWindow `window` to the provided UIWindowScene `scene`.
    // If using a storyboard, the `window` property will automatically be initialized and attached to the scene.
    // This delegate does not imply the connecting scene or session are new (see `application:configurationForConnectingSceneSession` instead).
    
    if (@available(iOS 13.0, *)) {
        UIWindowScene *windowScene = (UIWindowScene *)scene;
        self.window = [[UIWindow alloc] initWithWindowScene:windowScene];
        
        TATimerHomeVC *controller = [[TATimerHomeVC alloc]init];
        UINavigationController *nav = [[UINavigationController alloc]initWithRootViewController:controller];
            
        self.window.rootViewController = nav;
        [self.window makeKeyAndVisible];
    }
    
}
上一篇 下一篇

猜你喜欢

热点阅读