Subclass of UITextField that shows inline suggestions while typing.

Overview

AutocompleteField

CocoaPods Compatible Platform

Subclass of UITextField that shows inline suggestions while typing.

  • Plug and play replacement for UITextField.
  • Delimiter support. Perfect when autocompleting email addresses.
  • Two suggestion modes (word and sentence, see API below).
  • Works with custom fonts, borders etc.
  • Super lightweight and zero dependencies.

AutocompleteField

Requirements

  • iOS 10.0+
  • Swift 4.2+

Installation

CocoaPods

Add the following to your Podfile:

target 'MyApp' do
  pod 'AutocompleteField', '~> 2.0'
end

Swift Package Manager

  • Select File > Swift Packages > Add Package Dependency.
  • Enter https://github.com/filipstefansson/AutocompleteField.git in the Choose Package Repository dialog.

See Apple docs for more information.

Manually

  • Copy /Sources/AutocompleteField.swift to your project. There are no other dependencies.

Usage

You use this textfield in the same way as the regular UITextField, through Storyboards or programmatically.

Basic

import AutocompleteField

...

let textfield = AutocompleteField(frame: CGRect(x: 20, y: 20, width: 200, height: 40))
textfield.placeholder = "Name"

textfield.suggestions = [
  "George Washington",
  "Thomas Jefferson",
  "John Adams",
  "Theodore Roosevelt",
  "John F. Kennedy",
  "George W. Bush",
]

self.view.addSubview(textfield)

Delimiter

The delimiter can be used to only suggest an autocompletion after a specific character is found in the string. In this example we look for the @ character, and then provide suggestions for email providers.

import AutocompleteField

...

// email textfield autocompleting email providers
let textfield = AutocompleteField(frame: CGRect(x: 20, y: 20, width: 200, height: 40))
textfield.placeholder = "Email"
textfield.keyboardType = .emailAddress

textfield.suggestions = [
  "gmail.com",
  "icloud.com",
  "outlook.com",
]

// add the delimiter
textfield.delimiter = "@"

self.view.addSubview(textfield)

API

Property Type Description
suggestionColor UIColor The color of the suggestion. Defaults to the default placeholder color.
suggestion String The current suggestion shown. Read only.
suggestions [String] Array of suggestions.
suggestionType SuggestionType The type of suggestion that should be used. .Word will only hint the the next word in the suggestion and .Sentence will show the whole suggestion. Defaults to .Sentence.
pixelCorrections CGPoint Move the suggestion label up/down left/right. Use this to correct any differences if the suggestion doesn't match the input value for some reason.
horizontalPadding CGFloat Add padding to your textfield. Automatically set when using a borderStyle that has padding.
delimiter String Add a delimiter to only show a suggestion if there's more than one occurance of the delimiter. Perfect for autocompleting email providers.

Demo

Check out the example project.

License

AutocompleteField is provided under the MIT License. See LICENSE for details.

You might also like...
🏄‍♂️ UITextField-Navigation makes it easier to navigate between UITextFields and UITextViews
🏄‍♂️ UITextField-Navigation makes it easier to navigate between UITextFields and UITextViews

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

Animated UITextField enhance UX for the user by giving clarity that they are focused
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

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

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

UITextField category that adds shake animation
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

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:

UITextField with underline and left image
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

UITextField and UITextView subclasses with placeholders that change into floating labels when the fields are populated with text.
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

UITextField that automatically formats text to display in the currency format
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

UITextField that support currency in the right way.
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

Comments
  • Problem when resignFirstResponder is call

    Problem when resignFirstResponder is call

    Hi there!

    I'm facing a problem when I call self.view.endEditing(true), the autocomplete textField doesn't loose focus. I solved this behavior by changing your method (locally):

        public override func resignFirstResponder() -> Bool {
            self.label.text = nil
            super.resignFirstResponder() // add this line
            return true
        }
    

    I'm the right way? Thank you.

    opened by tomcalmon 1
  • feat: version 2

    feat: version 2

    Version 2.0

    Version 2.0 includes a rewrite to make this library work with Swift 4.2 and above, and a new delimiter feature that can be used when autocompleting email providers.

    What's new:

    • Rewritten to work with Swift 4.2 and above (closes #3, closes #4, closes #5, closes #6, closes #7, closes #8).
    • Added delimiter feature.
    • Add Swift Package Manager support.

    Bug fixes:

    • Fix .Word mode (closes #1).

    Breaking changes:

    • suggestion is now read only.
    • autocompleteType has been renamed to suggestionType.
    • pixelCorrection has been renamed to pixelCorrections, and changed from a CGFloat to a CGPoint to support correcting both y and x axis.
    • padding has been renamed to horizontalPadding.
    • completionColor has been renmaed to suggestionColor.
    opened by filipstefansson 0
  • NSAttributedString range error

    NSAttributedString range error

    We should use NSString.length instead of String.count when dealing with NSRange and NSAttributedString. NSRange(location: 0, length: (labelText as NSString).length) is preferred to NSRange(location: 0, length:labelText.count). The error will occur when text is matching the suggestion "George😁Washington".

    opened by NickMeepo 0
Releases(2.0)
  • 2.0(Oct 13, 2020)

    Version 2.0 includes a rewrite to make this library work with Swift 4.2 and above, and a new delimiter feature that can be used when autocompleting email providers.

    What's new:

    • Rewritten to work with Swift 4.2 and above (closes #3, closes #4, closes #5, closes #6, closes #7, closes #8).
    • Added delimiter feature.
    • Add Swift Package Manager support.

    Bug fixes:

    • Fix .Word mode (closes #1).

    Breaking changes:

    • suggestion is now read only.
    • autocompleteType has been renamed to suggestionType.
    • pixelCorrection has been renamed to pixelCorrections, and changed from a CGFloat to a CGPoint to support correcting both y and x axis.
    • padding has been renamed to horizontalPadding.
    • completionColor has been renmaed to suggestionColor.
    Source code(tar.gz)
    Source code(zip)
  • 1.1(Nov 23, 2015)

Owner
Filip Stefansson
Co-founder @pixby.
Filip Stefansson
ARAutocompleteTextView is a subclass of UITextView that automatically displays text suggestions in real-time

ARAutocompleteTextView is a subclass of UITextView that automatically displays text suggestions in real-time. This is perfect for automatically suggesting the domain as a user types an email address, #hashtag or @alexruperez.

Alex Rupérez 261 Jun 29, 2022
An UITextField subclass to simplify country code's picking. Swift 5.0

Preview Installation NKVPhonePicker is available through CocoaPods. To install it, simply add the following line to your Podfile: pod 'NKVPhonePicker'

Nike Kov 140 Nov 23, 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
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
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
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
Transition from any SwiftUI Text view into an inline navigation bar title when the view is scrolled off-screen, as seen in Apple's TV & TestFlight iOS apps.

SwiftUI Matched Inline Title Transition from any SwiftUI Text view into an inline navigation bar title when the view is scrolled off-screen, as seen i

Seb Jachec 19 Oct 9, 2022
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
Fully-wrapped UITextField made to work entirely in SwiftUI

iTextField ⌨️ A fully-wrapped `UITextField` that works entirely in SwiftUI. ?? Get Started | Examples | Customize | Install | Get Started Install iTex

Benjamin Sage 89 Jan 2, 2023
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