[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.
What we need to do is:
- Delete the Main.storyboard
- 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.
- Add following code to the AppDelegate.m (And don’t forget to import ViewController)
- Run the code! (You can try to add background color to the root view controller to ‘prove’ it’s actually displayed)