IOS

关注公众号 jb51net

关闭
首页 > 软件编程 > IOS > iOS删除storyboard步骤

iOS开发删除storyboard步骤详解

作者:圣骑士Wind

这篇文章主要为大家介绍了iOS系列学习之删除storyboard步骤详解,有需要的朋友可以借鉴参考下,希望能够有所帮助,祝大家多多进步,早日升职加薪

删除iOS项目中的storyboard

删除项目中的storyboard, (变成一个纯代码的iOS UIKit项目), 需要几步?

删除storyboard

(截图换了一个项目名, 不要在意这些细节.)

用上自己的ViewController

在ViewController里写上自己的完美View. 比如:

import UIKit
class ViewController: UIViewController {
    override func loadView() {
        view = UIView()
        view.backgroundColor = .systemBlue
    }
    override func viewDidLoad() {
        super.viewDidLoad()
        // Do any additional setup after loading the view.
    }
}

设置新的rootViewController.

class SceneDelegate: UIResponder, UIWindowSceneDelegate {
    var window: UIWindow?
    func scene(_ scene: UIScene, willConnectTo session: UISceneSession, options connectionOptions: UIScene.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).
        guard let windowScene = (scene as? UIWindowScene) else { return }
        let window = UIWindow(windowScene: windowScene)
        window.rootViewController = ViewController()
        self.window = window
        window.makeKeyAndVisible()
    }
 ...
import UIKit
@main
class AppDelegate: UIResponder, UIApplicationDelegate {
var window: UIWindow?
    func application(_: UIApplication, didFinishLaunchingWithOptions _: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
        window = UIWindow(frame: UIScreen.main.bounds)
        window?.rootViewController = ViewController()
        window?.makeKeyAndVisible()
        return true
    }
...

运行程序, 看到自己在ViewController里设置的View.

以上就是iOS开发删除storyboard步骤详解的详细内容,更多关于iOS删除storyboard步骤的资料请关注脚本之家其它相关文章!

您可能感兴趣的文章:
阅读全文