How to create login screen with alert view Controller using UIAlertController in SWIFT

Alert views can also be used with text field. You can use it to quickly get some input text to image or table.How to take text input with alert view.
1. First lets set up the x code project as usual. Create new single view application X code project. Set the values as follows and save it on your desktop.

2. Go to main storyboard and select view controller. Set its size iPhone 4-inch in attribute section.

3. Add button to main storyboard & rename it to Log In

4. Connect button to view controller swift file

5. Create a function/method as following just below view did load


This will just print username & password collected from log in screen.

6. Now add following code in Log In button we just created.

Here login control is created with alert view style.

Login action is created with two text fields. One for username & another for password. Then input text is printed with printText method. But login action is disabled here at the end.

Here sign up action, forgot password action & cancel action is created.

First text fields placeholder & keyboard type is set. Login action is enabled only if first text field is not empty.

Second text Fields place holder is set. And input is hidden like password.

All actions are added to login control

Login control is presented with animation.

7. Now build and run the app on iPhone 5s And click on Log In button.


Passionate about coding and software development holding 10+ Years of experience including 6+ years of experience on Mobile application Development.

More Posts