使用XCode11.2.1創建swift5純代碼主頁

作爲老iOS程序猿,受不了xid和storyboard頁面的大文件,佈局麻煩,更喜歡純代碼頁面簡單靈活,動態修改。開始學習swift了,還是喜歡純代碼頁面。並且由於我們程序猿的強迫症,也想第一個頁面也是純代碼頁面。
經過實踐,通過XCode11.2.1創建的swift工程,Launch Screen File不能是原來的LaunchImage.launchimage。那隻好採用默認的LaunchScreen.storyboard(LaunchScreen.xib應該也可以)。
想做成首頁是純頁面:
1.刪除Main.storyboard,SceneDelegate.swift和ViewController.swift文件。
2.在Info.plist文件中刪除Main storyboard file base name屬性和Application Scene Manifest屬性。
3.創建簡單首頁:HomeViewController.swift。
4.在AppDelegate.swift文件的didFinishLaunchingWithOptions函數中增加頁面代碼:

        self.window = UIWindow.init(frame: UIScreen.main.bounds)

        let login = UINavigationController.init(rootViewController: HomeViewController())

        self.window?.rootViewController = login
        self.window?.backgroundColor = UIColor.white

        self.window?.makeKeyAndVisible()

5.註釋下面的函數:

//    func application(_ application: UIApplication, configurationForConnecting connectingSceneSession: UISceneSession, options: UIScene.ConnectionOptions) -> UISceneConfiguration {
//        // Called when a new scene session is being created.
//        // Use this method to select a configuration to create the new scene with.
//        return UISceneConfiguration(name: "Default Configuration", sessionRole: connectingSceneSession.role)
//    }
//
//    func application(_ application: UIApplication, didDiscardSceneSessions sceneSessions: Set<UISceneSession>) {
//        // Called when the user discards a scene session.
//        // If any sessions were discarded while the application was not running, this will be called shortly after application:didFinishLaunchingWithOptions.
//        // Use this method to release any resources that were specific to the discarded scenes, as they will not return.
//    }

我就是因爲沒有把他們報錯,瞎折騰了好久。
6.當然在Targets->Build Settings->Swift Language Version設置爲Swift5。
工程代碼

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章