Better Programming

Advice for programmers.

Follow publication

Member-only story

Create Phone Number TextField With Country Codes and Flags in SwiftUI

A beautiful way to ask your users for their contact info

Sarah
Better Programming
Published in
3 min readSep 8, 2020
phone number textfield, text field, country code swiftui, country flag swiftui, phone number swiftui
Photo by the author.

We will present two methods of creating a phone number view that displays a country code and its flag. The first method contains a list of all the country codes for the user to pick. The second method will show the relevant flag whenever the user enters a valid country code.

First Method

Country code functions

Create a view struct that contains a dictionary of all the country codes we are going to have:

To have the full country name in your application, add the function below that takes in a country code and returns the full name:

Create an account to read the full story.

The author made this story available to Medium members only.
If you’re new to Medium, create a new account to read this story on us.

Or, continue in mobile web

Already have an account? Sign in

Responses (5)

Write a response