广告
返回顶部
首页 > 资讯 > 移动开发 >iOS开发删除storyboard步骤详解
  • 462
分享到

iOS开发删除storyboard步骤详解

iOS删除storyboard步骤iOS storyboard 2022-11-13 19:11:30 462人浏览 薄情痞子
摘要

目录删除iOS项目中的storyboard删除storyboard用上自己的ViewController删除ioS项目中的storyboard 删除项目中的storyboard, (

删除ioS项目中的storyboard

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

  • 找到storyboard, 删掉它.
  • 直接用ViewController.

删除storyboard

  • 首先, 你得有(新建)一个storyboard项目.
  • 删除storyboard. 选"Move to Trash".
  • 删除plist中的storyboard name.

  • 删除deploy target中的Main Interface, 本来是”main”, 把它变为空.

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

用上自己的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.

  • SceneDelegate中设置rootViewController. (iOS 13)
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()
    }
 ...
  • tvOS没有SceneDelegate (或者你想要兼容iOS 13以前的旧版本):
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步骤的资料请关注编程网其它相关文章!

--结束END--

本文标题: iOS开发删除storyboard步骤详解

本文链接: https://www.lsjlt.com/news/170908.html(转载时请注明来源链接)

有问题或投稿请发送至: 邮箱/279061341@qq.com    QQ/279061341

本篇文章演示代码以及资料文档资料下载

下载Word文档到电脑,方便收藏和打印~

下载Word文档
猜你喜欢
软考高级职称资格查询
编程网,编程工程师的家园,是目前国内优秀的开源技术社区之一,形成了由开源软件库、代码分享、资讯、协作翻译、讨论区和博客等几大频道内容,为IT开发者提供了一个发现、使用、并交流开源技术的平台。
  • 官方手机版

  • 微信公众号

  • 商务合作