IOS Company in Bangalore
  • Posted by:

    Shubam Gupta

    • June 30, 2020

    How to Build a Login Screen in SwiftUI

  • Blogs
  • How to Build a Login Screen in SwiftUI
  • Blogs
  • How to Build a Login Screen in Swif...

What is SwiftUI ?

In WWDC 2019 Apple announced a completely new user interface development framework called SwiftUI. SwiftUI is a user interface toolkit that lets us design apps in a declarative way. There was lots of talk about whether we should use Storyboard or build UI programmatically. SwiftUI is the answer to all these questions. You can now develop the app's UI with a declarative Swift syntax.

how-to-build-a-login-screen-in-swiftui-inner-1

No more storyboard, Interface Builder and Auto-layout

Earlier we used to develop user interfaces with storyboards, xib's and auto layout. But with SwiftUI, storyboard and auto-layout are completely out of the picture. Now the code editor is available with a preview canvas.

Migrating from UIKit to SwiftUI

If you've used UIKit before then you need to understand what's the UIKit component equivalent in SwiftUI. Many of the classes you know just by removing prefix UI but few have been renamed. Let's have a look at the list.

1. UIViewController: View

2. UITableViewController: List

3. UITabbarController: TabView

4. UINavigationController: NavigationView

5. UIAlertController: Alert

6. UIAlertController with style .actionSheet: ActionSheet

7. UILabel: Text

8. UITextField: TextField

9. UITextField with secure entry: SecureField

10. UISwitch: Toggle

11. UISlider: Slider

12. UIButton: Button

13. UIStackView with horizontal axis: HStack

14. UIStackView with vertical axis: VStack

15. UIImageView: Image

16. UISegmentedControl: SegmentedControl

17. UIStepper: Stepper

18. UIDatePicker: DatePicker

19. UIPickerView: Picker

20. UITabbar: TabView

21. UINavigationBar: NavigationView

22. UIScrollView: ScrollView

Creating Project:

Step 1 - Creating a new project with SwiftUI

Step 2 - Add the VStack in the View. It will act as Vertical StackView

Step 3 - Add title text as Login in the View and can set style to the Text.

Step 4 - Adding Image to the top of the Screen to show that its user's login and adding frame of width and height as shown below.

how-to-build-a-login-screen-in-swiftui-inner-2

Fig 1 - Adding Image and Text

Step 5 - Adding Text Field for Phone Number and password with TestField and SecureField inside the VStack and Alignment to leading.

Step 6 - Adding placeholder to the textfield , Add Text and Value will be saved in the Variable.

Step 7 - Give Divider() for allowing space between two textfield and add style as required for the textfield to be displayed.

Step 8 - Adding padding to bottom and given 15.

Step 9 - Adding Button of forgot password inside the HStack to align the right corner of the screen with the Text as shown below.

how-to-build-a-login-screen-in-swiftui-inner-3

Fig 2 - Adding Textfield and SecureField with Forget Password

Step 10 - Add a button with the title “Login” for clicking the login functionality inside the VStack.

Step 11 - In this button Action will be added inside the action closure function and can add text to the button (i.e Title) and Style the button as shown.

how-to-build-a-login-screen-in-swiftui-inner-4

Fig 3 - Adding Button with Action and Text

Step 12 - Add a button which will have an action to move to SignUp Screen inside the HStack with spacing. Where the SignUp text will be clickable which we implement using Attribute text Similarly in SwiftUI it is implemented in Simple Way.

how-to-build-a-login-screen-in-swiftui-inner-5

Fig 4 - "Don't have an Account ? Sign Up"

Final Result - Login Screen with PhoneNumber and Password using SwiftUI

how-to-build-a-login-screen-in-swiftui-inner-6

Conclusion

SwiftUI is new to everyone and might take time to get stable as a framework. But SwiftUI is the future of iOS development. There are a lot of things to learn in SwiftUI. 

Contact Appiness Interactive, a trustworthy IOS Company in Bangalore to build your website effectively.

TOP