Simple Navigation In Swift

Introduction

 
In this article, I will explain how to navigate from one page to another using Swift.
 
Pre-requisites
  • MacOS
  • XCode
So let’s get started,
  1. Open XCode and create a New Project.

    Simple Navigation In Swift

  2. Select iOS-> Single View App and Click Next.

    Simple Navigation In Swift

  3. Name your project and select the language as Swift. Check Use Core Data and Include Unit Tests. You may not require Core Data and Unit Tests in this application but as you go on learning further you will get to know about them. After you have done this, click Next.

  4. Choose a desired location where you want to save your project and click Create. So, your project is created in your desired location.

  5. Now you see a blank View Controller on your Screen. This is where we will create our UI.

  6. In the Object Library, you will get all the tools to design your UI. Just type the tool name you need at the bottom, and when it appears in the Object Library, drag and drop it in your View Controller.

    Simple Navigation In Swift

  7. You can change the Background color, Text color, Font size, etc as per your requirements in the Attributes Inspector.

  8. You can also rename your tool by double-clicking on it as shown in the figure.

    Simple Navigation In Swift

  9. So, I have designed my UI. Now I want to navigate to the next page by clicking on the Login button. For that, first of all, I will drag and drop a View Controller from my Object Library.

    Simple Navigation In Swift

  10. I will design my Second Page as a Welcome Page. Now, we need to perform navigation between the pages. For that, just press Ctrl and select the Login button and drag your mouse to the Second View Controller. You will see a blue line while performing this operation as shown in the figure.

    Simple Navigation In Swift
  1. When you release the mouse, a black box will appear. Select Show. This will create navigation between your View Controllers.

    Simple Navigation In Swift

  2. So, we have completed the Navigation.

  3. Run your project and check if the navigation works in your simulator as well as in your iPhone device.


Similar Articles