How to Create and Customize a TextField in SwiftUI

UITextField, evolved

Kelvin Tan
Swiftly Engineered iOS

--

Photo by Jelleke Vanooteghem on Unsplash

TextField, also known as UITextField, is one of the most commonly-used components in UIKit. Without TextField, you can’t input your email, password, or information.

Without these, you won’t be able to get information from your customers. With SwiftUI, as you already know, there are a lot of ways to customize it and this is so much easier compared to UIKit.

“A control that displays an editable text interface.” — Apple docs

In this tutorial, you’ll learn what it takes to build a TextField in SwiftUI. You’ll learn how to build a List.

Prerequisites

To follow along with this tutorial, you’ll need some basic knowledge:

  • A basic familiarity with Swift.
  • At least Xcode 11.

Basic Text Field

To build your first text field, simply type out the following code:

TextField("Enter your first name", text: $firstName).textFieldStyle(RoundedBorderTextFieldStyle())

Remember to create a variable to bind your text field with the following code. Now you can access the output by simply using the variable…

--

--

Kelvin Tan
Swiftly Engineered iOS

Father, husband, software engineer. Building software and building a family, one line of code and one moment at a time. 🚀💻💙 http://ko-fi.com/kelvintanzy