iTextField

0.0.3

Fully-wrapped UITextField made to work entirely in SwiftUI
benjaminsage/iTextField

iTextField ⌨️

A fully-wrapped `UITextField` that works entirely in SwiftUI. 🦅

Get Started | Examples | Customize | Install | Usage

CI


Get Started

  1. Install iTextField
  2. Add iTextField to your project
import SwiftUI
import iTextField

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

    var body: some View {
        iTextField("Placeholder", text: $text)
    }
}
  1. Customize your iTextfield

Examples

Starter

drawing

Customize your text field with built-in modifiers.
import SwiftUI
import iTextField

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

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

Jump text fields

Use the optional isEditing binding parameter to programmatically jump between text fields.

import SwiftUI
import iTextField

struct ContentView: View {
    @State var text1: String = ""
    @State var text2: String = ""
    @State var isSecondEditing: String = ""

    var body: some View {
        iTextField("First", text: $text1)
            .onReturn { isSecondEditing = true }
        iTextField("Second", text: $text2,
                   isEditing: $isSecondEditing)
    }
}

Customize

iTextField has two required parameters: 1️⃣ a placeholder and 2️⃣ a text state. You can optionally pass in a 3️⃣rd an isEditing binding if you would like to programmatically focus or unfocus the text field.

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 this exhaustive input list to customize your text field.

Modifier Description
.fontFromUIFont(_ font: UIFont?) Modifies the text field’s font from a UIFont object. 🔠
.foregroundColor(_ color: Color?) Modifies the text color 🎨 of the text field.
.accentColor(_ accentColor: Color?) Modifies the cursor color 🌈 of the text field
.multilineTextAlignment(_ alignment: TextAlignment) Modifies the text alignment of a text field. ↔️
.textContentType(_ textContentType: UITextContentType?) Modifies the content type of a text field. 📧 ☎️
.disableAutocorrection(_ disable: Bool?) Modifies the text field’s autocorrection settings.
.keyboardType(_ type: UIKeyboardType) Modifies the text field’s keyboard type. 📩
.autocapitalization(_ style: UITextAutocapitalizationType) Modifies the text field’s autocapitalization style. 🔡
.returnKeyType(_ type: UIReturnKeyType) Modifies the text field’s return key type.
.isSecure(_ isSecure: Bool) Modifies the text field’s secure entry settings. 🔒
.clearsOnBeginEditing(_ shouldClear: Bool) Modifies the clear-on-begin-editing setting of a text field.
clearsOnInsertion(_ shouldClear: Bool) Modifies the clear-on-insertion setting of a text field. 👆
.showsClearButton(_ showsButton: Bool) Modifies whether and when the text field clear button appears on the view. ⭕️
.passwordRules(_ rules: UITextInputPasswordRules) Modifies the text field's password rules 🔒. Sets secure entry to true.
.spellChecking(_ spellChecking: Bool? = nil) Modifies whether the text field should check the user's spelling.
.smartDashes(_ smartDashes: Bool? = nil) Modifies whether the text field includes smart dashes.
.smartInsertDelete(_ smartInsertDelete: Bool? = nil) Modifies whether the text field uses smart insert-delete.
.smartQuotes(_ smartQuotes: Bool? = nil) Modifies whether the text field uses smart quotes.
.disabled(disabled: Bool) Modifies whether the text field is disabled.
.onEditingBegan(perform action: { code }) Modifies the function called when text editing begins. ▶️
.onEdit(perform action: { code }) Modifies the function called when the user makes any changes to the text in the text field. 💬
.onEditingEnded(perform action: { code }) Modifies the function called when text editing ends. 🔚
.onReturn(perform action: { code }) Modifies the function called when the user presses the return key. ⬇️ ➡️
.onClear(perform action: { code }) Modifies the function called when the user clears the text field.

Install

Use the Swift package manager to install. Find instructions here😀

Usage

iTextField is FREE and open-source for individuals, and will remain that way forever.

iTextField is distributed under a GNU GPL open-source license.

Commercial users, please note, this license is often incompatible for many commercial applications. If your app is distributed for commercial use, it could violate this open-source license even "if the application is free in the App Store".

In order to offer iTextField safely to our commercial friends we made it easy to purchase a lifetime, full-use license for $4.99. Code on worry free 😁

Description

  • Swift Tools 5.3.0

Dependencies

  • None
Last updated: Thu Dec 03 2020 07:13:18 GMT-0500 (GMT-05:00)