iTextField

Quickly implement a textfield with all the UIKit capabilities 💪 in SwiftUI. 😲

1.

Install iTextField.

2.

Add iTextField to your project.

import SwiftUI
import iTextField

struct ContentView: View {
    @State var text: String = ""
    @State var isEditing: Bool = false

    var body: some View {
        iTextField("Placeholder",
                   text: $text,
                   isEditing: $isEditing)
    }
}

3.

Customize your iTextField.



Examples

Starter

Customize your textfield with our built in modifiers.

import SwiftUI
import iTextField

struct ContentView: View {
    @State var text: String = ""
    @State var isEditing: Bool = false

    var body: some View {
        iTextField("Placeholder", text: $text, isEditing: $isEditing)
            .accentColor(.purple)
            .fontFromUIFont(UIFont(name: "Avenir", size: 40))
            .keyboardType(.URL)
            .returnKeyType(.done)
            .disableAutocorrection(true)
            .autocapitalization(.none)
            .padding()
    }
}

Customize

iTextField has three required parameters: 1️⃣ a placeholder, 2️⃣ a text state, and 3️⃣ an isEditing state. iTextField also supports a variety of modifiers.

Example: Change the foreground color, accent color, and text alignment with the following code block:

iTextField("Placeholder", text: $text, isEditing: $isEditing)
    .foregroundColor(.purple)
    .accentColor(.green)
    .multilineTextAlignment(.leading)

Use our exhaustive input list to customize your text field.

Modifier Description
.fontFromUIFont(font: UIFont?) -> iTextField
Modifies the text field’s font from a UIFont object. 🔠🔡
.foregroundColor(color: Color?) -> iTextField
Modifies the text color 🎨 of the text field.
.accentColor(accentColor: Color?) -> iTextField
Modifies the cursor color 🌈 of the text field 🖱💬
.multilineTextAlignment(alignment: TextAlignment) -> iTextField
Modifies the text alignment of a text field. ⬅️↔️➡️
.textContentType(textContentType: UITextContentType?) -> iTextField
Modifies the content type of a text field. 📧☎️📬
.disableAutocorrection(disable: Bool?) -> iTextField
Modifies the text field’s autocorrection settings. 💬
.keyboardType(type: UIKeyboardType) -> iTextField
Modifies the text field’s keyboard type. 📩🕸🧒
.autocapitalization(style: UITextAutocapitalizationType) -> iTextField
Modifies the text field’s autocapitalization style. 🔡🔠
.returnKeyType(type: UIReturnKeyType) -> iTextField
Modifies the text field’s return key type. 🆗✅
.isSecure(isSecure: Bool) -> iTextField
Modifies the text field’s secure entry settings. 🔒🚨
.clearsOnBeginEditing(shouldClear: Bool) -> iTextField
Modifies the clear-on-begin-editing setting of a text field. ❌▶️
.disabled(disabled: Bool) -> iTextField
Modifies whether the text field is disabled. ✋
.onEditingBegan(action: { code }) -> iTextField
Modifies the function called when text editing begins. ▶️
.onEdit(action: { code }) -> iTextField
Modifies the function called when the user makes any changes to the text in the text field. 💬
.onEditingEnded(action: { code }) -> iTextField
Modifies the function called when text editing ends. 🔚

Community

Meet the developers behind iTextField.


@benjaminsage


iOS 13.0+

WatchOS 6.0+