[iOS][Objc] Get started on building UI programmatically

Sometimes we’d like to build our iOS App UI programmatically because the iOS App is too complex, or maybe the App is a team work, or we want to easily reuse the views. But, how to do that?

Every time when you create a new project, let’s say a Single View App, the Xcode will create a storyboard for you. And just delete it won’t let you make the app run.

Auto created storyboard

What we need to do is:

  1. Delete the Main.storyboard
  2. Click the Project in the Navigator Area (e.g. the ‘NoStoryBoard’ project in the screenshot above) and in ‘General’ Tab -> Deployment Info -> Main Interface, delete the ‘Main’ in the text field.
  3. Add following code to the AppDelegate.m (And don’t forget to import ViewController)
  4. Run the code! (You can try to add background color to the root view controller to ‘prove’ it’s actually displayed)