Xcode11 programmatically layout preparation without Storyboard
How to delete Main.storyboard and how to prepare UIKit programmatically layout in Xcode11.
1. Create a new project in Xcode11 with Swift and Storyboard
Choose Swift and Storyboard.
2. Delete “Main.storyboard” in the Navigation pane
3. Delete “Main” letter
Navigation pane → PROJECT-NAME → TARGETS → General → Deployment Info → Main Interface
4. Remove the item “Storyboard Name" in Info.plist
Expand Info.plist
→ Application Scene Manifest
(expand)→ Scene Configuration
(expand) → Application Session Role
(expand) → Item 0 (Default Config…
(expand). Delete the item “Storyboard Name” .
5. Replace defaultscene(_:willConnectTo:options:)
to the following code:
func scene(_ scene: UIScene, willConnectTo session: UISceneSession, options connectionOptions: UIScene.ConnectionOptions) {guard let windowScene = (scene as? UIWindowScene) else { return }window = UIWindow(frame: UIScreen.main.bounds)let viewController = ViewController()window?.rootViewController = viewControllerwindow?.makeKeyAndVisible()window?.windowScene = windowScene}
For example,
5. Try test run after adding some code in ViewController.swift
Add some code in ViewController.swift
.
For example:
import UIKitclass ViewController: UIViewController { override func viewDidLoad() { super.viewDidLoad() // Do any additional setup after loading the view. view.backgroundColor = .cyan }}
After adding the bellow code, try run this project. If successful, iOS simulator will show up colored background.