ARAutocompleteTextView is a subclass of UITextView that automatically displays text suggestions in real-time

Overview

ARAutocompleteTextView

Twitter GitHub Issues Version Status License Status Platform Status Analytics

Overview

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 @handle.

ARTextViewAutocompletion

Usage

Installation

Add the following files to your project:

  • ARAutocompleteTextView.m
  • ARAutocompleteTextView.h
  • ARAutocompleteManager.m
  • ARAutocompleteManager.h

Quickstart Guide

Create an ARAutocompleteTextView instance exactly as as you would UITextView. You can do eith either programmitcally or in Interface Builder. Programmatically, this looks like:

Objective C
ARAutocompleteTextView* textField = [[ARAutocompleteTextView alloc] initWithFrame:CGRectMake(0,0,100,31)];
Swift
let textField = ARAutocompleteTextView(frame: CGRectMake(0, 0, 100, 31))

The data source is the brains of the autocomplete logic. If you just want to autocomplete email addresses, #hashtags or @handles, use ARAutocompleteManager from the example project as follows:

Objective-C
textField.autocompleteDataSource = [ARAutocompleteManager sharedManager];
textField.autocompleteType = ARAutocompleteTypeEmail;
Swift
textField.autocompleteDataSource = ARAutocompleteManager.sharedManager()
textField.autocompleteType = ARAutocompleteType.Mail

Customization

Autocompletion Data Source

ARAutocompleteManager (included in the example project) provides email address autocompletion out of the box. It comes with a list of the top email domains. You may want to tailor this list of email domains to match your own customers, or you may want to write autocomplete logic for a different type of text view (in the demo, names of colors are autocompleted).

Alternatively, you may wish to create your own data source class and user the autocompleteType property to differentiate between textviews with different data types. A ARAutocompleteTextView's data source must implement the following method, as part of the ARAutocompleteDataSource protocol.

- (NSString *)textField:(ARAutocompleteTextView*)textField completionForPrefix:(NSString *)prefix

You may also set a default dataSource for all instances of ARAutocompleteTextView. In the example project, we use a ARAutocompleteManager singleton:

 [autocompleteTextOffset setDefaultAutocompleteDataSource:[ARAutocompleteManager sharedManager]];

Positioning and Formatting

To adjust the position of the autocomplete label by a fixed amount, set autocompleteTextOffset:

textField.autocompleteTextOffset = CGPointMake(10.0, 10.0);

For more dynamic positioning of the autocomplete label, subclass ARAutocompleteTextView and override - (CGRect)autocompleteRectForBounds:(CGRect)bounds.

To adjust the properties (i.e. font, textColor) of the autocomplete label, do so via the `[AutocompleteTextField autocompleteLabel] property.

textField.autocompleteLabel.textColor = [UIColor grayColor];

Event Listening

In addition to observing the standard UITextView notifications (i.e. UITextViewTextDidChangeNotification and friends), you can use [ARAutocompleteTextView autoCompleteTextFieldDelegate] to listen for certain events. This is particularly useful if you are collecting analytics.

Etc.

  • Use this in your apps whenever you can, particularly email addresses -- your users will appreciate it!
  • Contributions are very welcome.
  • Attribution is appreciated (let's spread the word!), but not mandatory.

Use it? Love/hate it?

Tweet the author @alexruperez, and check out alexruperez's blog: http://alexruperez.com

Other Links

code4app Review

Cocoa Controls

Comments
  • Double press space bar no longer inserts a period

    Double press space bar no longer inserts a period

    Originally, the shortcut to insert a period is double pressing the space bar quickly. That seems to be disabled in ARAutocompleteTextView. I'll look into it and submit a pull request if I can solve it.

    opened by inb4ohnoes 6
  • I did my version for Swift!

    I did my version for Swift!

        ARAutocompleteTextView.setDefaultAutocompleteDataSource(ARAutocompleteManager.sharedManager())
        let singletap: UITapGestureRecognizer = UITapGestureRecognizer(target: self, action: "handleSingleTap:")
        // Dismiss the keyboard when the user taps outside of a text field
       self.view.addGestureRecognizer(singletap)
    
    }
    func handleSingleTap(recognizer : UIRotationGestureRecognizer)
    {
        self.txtEmail.becomeFirstResponder()
        self.txtEmail.resignFirstResponder()
    }
    
    func textView(textView: UITextView, shouldChangeTextInRange range: NSRange, replacementText text: String) -> Bool {
        if text=="\n"
        {
            self.txtPassword.becomeFirstResponder()
    
            return false
        }
        return true
    
    }
    
    opened by lfarah 1
  • Licensing

    Licensing

    Looks neat, but LGPL will likely mean that anyone who wants to use it will be unable to. Recommend considering Apache 2.0, MIT, or another similar license.

    opened by aaronbrethorst 1
  • Add a Gitter chat badge to README.md

    Add a Gitter chat badge to README.md

    opened by gitter-badger 0
  • error with commit autocompleteString

    error with commit autocompleteString

    When there is a space in my custom prompt text, after submitting the auto-completion, deleting will cause problems. When you encounter a space, submit the auto-completion again.

    bug hacktoberfest 
    opened by cugxy 0
  • convert to Swift 3 syntax

    convert to Swift 3 syntax

    This just converted the Swift Example branch to Swift 3, probably keep this on it's own branch as an optional as some people are still using 2.3 at this point.


    This change is Reviewable

    hacktoberfest 
    opened by coderbec 0
Releases(0.1.0)
Owner
Alex Rupérez
Tech Director
Alex Rupérez
An auto-layout base UITextView subclass which automatically grows with user input and can be constrained by maximal and minimal height - all without a single line of code

Deprecated This library is no longer maintained and is deprecated. The repository might be removed at any point in the future. MBAutoGrowingTextView A

Matej Balantič 125 Jan 13, 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 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
A light-weight UITextView subclass that adds support for placeholder.

RSKPlaceholderTextView A light-weight UITextView subclass that adds support for placeholder. Installation Using Swift Package Manager To add the RSKPl

Ruslan Skorb 220 Dec 17, 2022
A UITextView subclass that adds support for multiline placeholder written in Swift.

KMPlaceholderTextView A UITextView subclass that adds support for multiline placeholder written in Swift. Usage You can set the value of the placehold

Zhouqi Mo 795 Nov 18, 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
UILabel subclass to perform text effects

CharacterText uses NSLayoutManager to position CATextLayers for each glyph in your string. This gives you the power to create some neat text effect using all the attributes of CATextLayer.

null 333 Sep 15, 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
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
An UITextView in Swift. Support auto growing, placeholder and length limit.

GrowingTextView Requirements iOS 8.0 or above Installation CocoaPods GrowingTextView is available through CocoaPods. To install it, simply add the fol

Kenneth Tsang 941 Jan 5, 2023
DGPlaceholderTextView - A light-weight UITextView that supports for placeholder

DGPlaceholderTextView Requirements Installation Usage Properties DGPlaceholderTe

donggyu 5 Jan 26, 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
AEOTPTextField - A beautiful iOS OTP Text Field library, written in Swift with full access customization in UI.

AEOTPTextField - A beautiful iOS OTP Text Field library, written in Swift with full access customization in UI.

Abdelrhman Kamal 79 Jan 3, 2023
A beautiful and flexible text field control implementation of "Float Label Pattern". Written in Swift.

SkyFloatingLabelTextField SkyFloatingLabelTextField is a beautiful, flexible and customizable implementation of the space saving "Float Label Pattern"

Skyscanner 4k Jan 1, 2023