删去iOS项目中的storyboard
删去项目中的storyboard, (变成一个纯代码的iOS UIKit项目), 需要几步?
- 找到storyboard, 删掉它.
- 直接用ViewController.
删去storyboard
- 首先, 你得有(新建)一个storyboard项目.
- 删去storyboard. 选”Move to Trash”.
- 删去plist中的storyboard name.
![[Android开发学iOS系列] 删除storyboard需要几步 [Android开发学iOS系列] 删除storyboard需要几步](https://www.6hu.cc/wp-content/uploads/2022/12/1671710089-767e9bdb4344c3e.png)
- 删去deploy target中的Main Interface, 本来是”main”, 把它变为空.
![[Android开发学iOS系列] 删除storyboard需要几步 [Android开发学iOS系列] 删除storyboard需要几步](https://www.6hu.cc/wp-content/uploads/2022/12/1671710093-eaacd009ac1270c.png)
注意xcode 14之后改为删去这儿的文字”Main”:
![[Android开发学iOS系列] 删除storyboard需要几步 [Android开发学iOS系列] 删除storyboard需要几步](https://www.6hu.cc/wp-content/uploads/2022/12/1671710099-038e7b635bbf869.png)
用上自己的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.
Ta-da!
声明:本站所有文章,如无特殊说明或标注,均为本站原创发布。任何个人或组织,在未征得本站同意时,禁止复制、盗用、采集、发布本站内容到任何网站、书籍等各类媒体平台。如若本站内容侵犯了原著者的合法权益,可联系我们进行处理。