Fully-wrapped UITextField made to work entirely in SwiftUI

Overview

iTextField ⌨️

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

Get Started | Examples | Customize | Install |

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.
.characterLimit(_ limit: Int?) Sets the maximum amount of characters allowed in this text field.
.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 😀

Help

As always, if you have any questions about iPhoneNumberField, we are available 24/7 to help.

Reach us at
📞 +1 (415) 735-4464 Call
📧 [email protected] Email
📲 +1 (415) 735-4464 Text
Comments
  • Fix Handling of Updating modifiers

    Fix Handling of Updating modifiers

    iTextValue currently does not react to changing values of modifiers.

    This PR fixes that by setting all the properties of TextView again in the updateUIView method.

    Works great in my testing.

    opened by nmn 2
  • Fix forced unwrap

    Fix forced unwrap

    This forced upward is causing a compile error in the newest release of xCode on my m1 mac. It might be related to M1 or just the newest version of Swift/XCode, but this fix should work either way.

    opened by nmn 1
  • Handle toggling isSecure correctly

    Handle toggling isSecure correctly

    There are two issues that occur when toggling isSecure on a textField, both happen when going from not-secure to secure.

    The first keyboard action after the textField becomes secure deletes all of the existing content within it.

    This commit fixes that by manually reading the contents of the field, manually removing them and updating them all from within the code when we go from a not-secure textfield to a secure textField.

    The workaround above causes the cursor position to always jump to the end of the text

    This commit fixes that by reading the cursor/selection state before updating the value of isSecureEntry and restoring it after the text has been removed and added back.

    This diff also refactors the code to remove duplication.

    opened by nmn 0
  • iTextField Review

    iTextField Review

    Again overall things are strong. It's like I'm reviewing a Ferrari. Sure I might want to change the paint job a bit, maybe swap the wheels, but the engine – the most important part – fucking roars.

    1. Unsure of the placeholder needs to be required. Had difficulty removing it for that use case. Probably want to toss that guy as an optional.

    2. clearsOnBeginEditing is a little unclear. I thought this meant that if I add a default value it will clear that value when I start to edit the text field. That wasn't what happened. Actually still unclear what this does. Whatever it is let's just rename it. Another quick fix.

    Screen Shot 2020-10-06 at 9 52 01 AM
    1. Same border & font comment as on iPhoneNumberTextField

    2. Click out to remove keyboard. I know this isn't trivial but I think that'd be an awesome feature to include. Click off the screen to remove the keyboard. Unsure how else to remove keyboard now. Not sure what to click.

    opened by AlexFine 0
  • AttributeGraph: cycle detected through attribute 234608

    AttributeGraph: cycle detected through attribute 234608

    When I have an iTextField that's first responder it creates attribute warnings. I added a Symbolic breakpoint with symbol print_cycle. It seems that Xcode doesn't like changing first responder they way its done below.

    public struct iTextField: UIViewRepresentable {
    ...
    public func updateView {
    ...
    if isEditing.wrappedValue {
        textField.becomeFirstResponder() // <- Causes the warning
    } else {
        textField.resignFirstResponder()
    }
    
    }}
    
    opened by solkpolk 1
  • Change license to MIT?

    Change license to MIT?

    Hi,

    first of all, thank you very much for this great library. It is very useful for everyone who is using SwiftUI but need more customisation for TextField

    But the GPL license is very quite restricted. People would need to open source the whole app when they use this library inside their app.

    Is it a possibility to change the license to a more commercial friendly one, such as MIT?

    Thank you in any case.

    opened by antranapp 0
Owner
Benjamin Sage
iOS frontend dev using SwiftUI 🤑
Benjamin Sage
HTYTextField A UITextField with bouncy placeholder.

HTYTextField - A UITextField with bouncy placeholder. Screenshot Installation CocoaPods Add the dependency to your Podfile

Hanton Yang 312 Nov 13, 2022
UITextField character counter with lovable UX 💖. No math skills required 🙃.

TextFieldCounter UITextField character counter with lovable UX ??. No math skills required ??. Features Set max length of UITextField. A beautiful an

Fabricio Serralvo 434 Dec 22, 2022
🏄‍♂️ UITextField-Navigation makes it easier to navigate between UITextFields and UITextViews

' __________________ _______ _________ _______ _________ _______ _ ______ ' |\ /|\__ __/\__ __/( ____ \|\ /

Thanh Pham 446 Nov 24, 2022
Animated UITextField enhance UX for the user by giving clarity that they are focused

JDCircularProgress JDTextField is animateable UITextField that can significantly enhance your user's experiences and set your app apart from the rest

Jawad Ali 22 Nov 17, 2022
Animated Subclass of UITextField created with CABasicAnimation and CAShapeLayer

JDAnimatedTextField JDAnimatedTextField is animateable UITextField that can significantly enhance your user's experiences and set your app apart from

Jawad Ali 25 Dec 13, 2022
This project will add a done button on your UITextField and UITextView

This project will add a done button on your UITextField and UITextView

Botla Venkatesh 0 Nov 23, 2021
UITextField subclass with floating labels

JVFloatLabeledTextField JVFloatLabeledTextField is the first implementation of a UX pattern that has come to be known the "Float Label Pattern". Due t

Jared Verdi 7.2k Jan 2, 2023
UITextField category that adds shake animation

UITextField category that adds a shake animation like the password field of the OsX login screen. Screenshot Setup with CocoaPods pod 'UITextField+Sha

Andrea Mazzini 749 Dec 13, 2022
UITextField extension in Swift that adds shake animation

UITextField-Shake-Swift UITextField extension in Swift that adds shake animation Initially created by Andrea Mazzini (using Objective-C) on 08/02/14:

null 15 Jul 20, 2021
iOS - Subclass of UITextField to achieve autocompletion for Place Search like Google Places, Uber and Much more apps having maps.

MVAutocompletePlaceSearchTextField iOS - Subclass of UITextField to achieve autocompletion for Place Search like Google Places, Uber and Much more app

Mrugrajsinh Vansadia 68 May 27, 2022
Subclass of UITextField that shows inline suggestions while typing.

AutocompleteField Subclass of UITextField that shows inline suggestions while typing. Plug and play replacement for UITextField. Delimiter support. Pe

Filip Stefansson 663 Dec 6, 2022
UITextfield subclass with autocomplete menu. For iOS.

MLPAutoCompleteTextField "We believe that every tap a user makes drains a tiny bit of their energy and patience. Typing is one of the biggest expendit

Eddy Borja 1.2k Nov 11, 2022
UITextField with underline and left image

TJTextField UITextField with underline and left image Version: 1.0 Features Add image in UITextField Left text pedding Underline whole UITextField Sho

Tejas Ardeshna 44 May 16, 2022
UITextField and UITextView subclasses with placeholders that change into floating labels when the fields are populated with text.

Deprecated Please use JVFloatLabeledTextField instead or feel free to chime in on an issue if you'd like to take over the repo. RPFloatingPlaceholders

rob phillips 1.1k Jan 5, 2023
UITextField that automatically formats text to display in the currency format

CurrencyTextField The numbers that the user enters in the field are automatically formatted to display in the dollar amount format. For example, if th

Richa Deshmukh 49 Sep 28, 2022
UITextField that support currency in the right way.

PLCurrencyTextField Summary PLCurrencyTextField provides simple and user friendly support for the amount in the currency. Usage To start using the com

Łukasz Śliwiński 96 Nov 14, 2022
Animated UITextField and UITextView replacement for iOS

AnimatedTextInput iOS custom text input component used in the Jobandtalent app. Installation Use cocoapods to install this custom control in your proj

jobandtalent 757 Dec 15, 2022
UITextField subclass with autocompletion suggestions list

SearchTextField Overview SearchTextField is a subclass of UITextField, written in Swift that makes really easy the ability to show an autocomplete sug

Alejandro Pasccon 1.1k Dec 28, 2022
UITextField-based control for (NS)Measurement values input.

MeasurementTextField UITextField-based control for (NS)Measurement values input. Provides type-safe keyboard and picker based input of different measu

Siarhei Fiedartsou 16 Jul 22, 2021