当前位置: 代码网 > it编程>App开发>苹果IOS > iOS开发删除storyboard步骤详解

iOS开发删除storyboard步骤详解

2024年05月18日 苹果IOS 我要评论
删除ios项目中的storyboard删除项目中的storyboard, (变成一个纯代码的ios uikit项目), 需要几步?找到storyboard, 删掉它.直接用viewcontroller

删除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步骤的资料请关注代码网其它相关文章!

(0)

相关文章:

版权声明:本文内容由互联网用户贡献,该文观点仅代表作者本人。本站仅提供信息存储服务,不拥有所有权,不承担相关法律责任。 如发现本站有涉嫌抄袭侵权/违法违规的内容, 请发送邮件至 2386932994@qq.com 举报,一经查实将立刻删除。

发表评论

验证码:
Copyright © 2017-2025  代码网 保留所有权利. 粤ICP备2024248653号
站长QQ:2386932994 | 联系邮箱:2386932994@qq.com