Hello Everyone!!!
Auto Layout is how we layout our UI in iOS applications. Learning how to use it programmatically can be overwhelming at first. In this introduction series, we’ll look at how to easily anchor elements onto the screen relative to other items.
Most of the times, Xcode shows errors regarding constraints in the main storyboards. So, it is better to code programmatically by using the anchors.
Let’s get started
Step 1:- Open Xcode, Select the main storyboard & delete it…(move to trash)
Step 2:- Now, go to the info.plist & delete the key of “Main Storyboard file base name”
Step 3:- To build our storyboard programmatically.…Go to the App Delegate & write the following code…
Here, we have created a new window with the reference of user’s physical device. “makeKeyAndVisible()” -> It will show the window & makes it key window. Then we have connected the storyboard window to the View Controller with the help of “RootViewController”.
Now, go to View Controller & write a small code to test our recently created new window
In view did load, type -> view?.backgroundColor = .blue
The simulator will show the blue background of window………..
Good Job! You just have created a new storyboard programmatically…
Comments
Post a Comment