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