In a new project select the empty View Controller
In the Editor menu select Embed In - Navigation Controller
Your editor should now look like this.
In the Attributes Inspector for the Navigation Controller make sure 'Is Inital View Controller' is selected
The Navigation Controller should now have this arrow pointing to it.
In the Attributes Inspector for the View Controller set the Title field to be 'Page 1'
Drag a button onto the View Controller
In the Attributes Inspector for the button set the fields as follows
- Font: Custom
- Family: Helvetica
- Style: Bold
- Size: 80
While the button is selected go to the Editor menu and select Size to Fit Content
While the button is selected, click on the align button and add the following contstraints and then press the 'Add 2 Contraints' button
- Horizontal Center in Container
- Vertical in Container
In the Object Library find the View Controller object and drag it onto the editor.
Position your the new View Controller to the right of the other one.
In the Object Library find a label and drag it onto the new View Controller
Set the label text to 'PAGE 2'
In the Attributes Inspector for the label set the fields as follows
- Font: Custom
- Family: Helvetica
- Style: Bold
- Size: 80
While the label is selected go to the Editor menu and select Size to Fit Content
While the label is selected, click on the align button and add the following
contstraints and then press the 'Add 2 Contraints' button
- Horizontal Center in Container
- Vertical in Container
Select the button on the Page 1 View Controller and hold down the 'Control' key and drag to the Page 2 View Controller
A popup will appear, select show.
Page 1 and Page 2 should now be linked.
Select the Page 2 View Controller
In the Attributes Inspector set the Title field to 'Page 2'
Run the app in the iOS Simulator and click the Page 1 button
You will navigate to Page 2. You will notice that the Navigation Controller has automatically added a back button.
Back in Xcode, select the Navigation Item in the Page 1 View Controller
In the Attributes Inspector for the Navigation Item set the Title field to Page 1
Run the app again in the iOS Simulator, notice the Page Title is now Page 1
If you navigate to page 2 the back button now says Page 1 instead of Back.
Back in Xcode, select the Navigation Item in the Page 1 View Controller
In the Attributes Inspector for the Navigation Item clear the value for the Title field and set the Back Button field to Home
Run the app in the iOS simulator again and navigate to Page 2. You will notice the back button now says Home.
If you rotate the app to the right you will notice the layout stays the same.
No comments:
Post a Comment