iOS開發刪除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步驟的資料請關註WalkonNet其它相關文章!
推薦閱讀:
- iOS閱讀器與直播的控件重疊滑動交互詳解
- Swift仿微信語音通話最小化時後的效果實例代碼
- swift實現簡易計算器項目
- iOS開發創建frame實現window窗口view視圖示例
- swift實現隨機背景色