Note: Intro to Programatic UI. No Storyboard – Swift – Xcode 10

Author: Sean Allen Video URL: Intro to Programatic UI. No Storyboard – Swift – Xcode 10 Introduction: In this video we build the basic structure of an app without using storyboards. We take a programatic approach to showing the initial screen, creating a UINavigationController, adding a UIButton to the screen, and transitioning to a new screen. This is just the beginning o your programatic UI journey!

Could not find a storyboard named ‘Main’ in bundle NSBundle

When CMD+R to run the project, will get the error of “Could not find a storyboard named ‘Main’ in bundle NSBundle” after deleting the default MainStoryboard file. The solution is to delete the propriety of “Main storyboard file base name” in the file of Info.plist.
Could not find a storyboard named 'Main' in bundle NSBundle
Could not find a storyboard named ‘Main’ in bundle NSBundle

Add initial view controller

    func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {

        let vc = ViewController()
        window = UIWindow(frame: UIScreen.main.bounds)
        window?.rootViewController = vc
        return true

Set Constraints by codes

    func setNextButtonConstraints() {
        nextButton.translatesAutoresizingMaskIntoConstraints = false
        nextButton.leadingAnchor.constraint(equalTo: view.leadingAnchor, constant: 20).isActive = true
        nextButton.trailingAnchor.constraint(equalTo: view.trailingAnchor, constant: -20).isActive = true
        nextButton.heightAnchor.constraint(equalToConstant: 50).isActive = true
        nextButton.centerYAnchor.constraint(equalTo: view.centerYAnchor).isActive = true
These four constraints will restrict the explicit position of nextButton in its super view i.e. view.

Add target for the button

/* This will add the specific target of "nextButtonTapped" to nextButton. */
nextButton.addTarget(self, action: #selector(nextButtonTapped), for: .touchUpInside)

/* The target function looks like as follows. */
@objc func nextButtonTapped() {
    /* TODO */


Fill in your details below or click an icon to log in: 徽标

您正在使用您的 账号评论。 注销 /  更改 )

Twitter picture

您正在使用您的 Twitter 账号评论。 注销 /  更改 )

Facebook photo

您正在使用您的 Facebook 账号评论。 注销 /  更改 )

Connecting to %s

这个站点使用 Akismet 来减少垃圾评论。了解你的评论数据如何被处理