iOS纯代码UI

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];
    }
    
}
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容