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
        window?.makeKeyAndVisible()
        
        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 */
}
 
Advertisements

分类:iOS

Tagged as: , ,

发表评论

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

WordPress.com 徽标

You are commenting using your WordPress.com account. Log Out /  更改 )

Google+ photo

You are commenting using your Google+ account. Log Out /  更改 )

Twitter picture

You are commenting using your Twitter account. Log Out /  更改 )

Facebook photo

You are commenting using your Facebook account. Log Out /  更改 )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.