GithubHelp home page GithubHelp logo

deracination / htautocompletetextfield Goto Github PK

View Code? Open in Web Editor NEW

This project forked from hoteltonight/htautocompletetextfield

0.0 2.0 0.0 2.14 MB

License: MIT License

Objective-C 98.90% Ruby 1.10%

htautocompletetextfield's Introduction

HotelTonight

HTAutocompleteTextField

Overview

HTAutocompleteTextField is a subclass of UITextField that automatically displays text suggestions in real-time. This is perfect for automatically suggesting the domain as a user types an email address.

You can see it in action in the animated gif below or on Youtube, or read about it in the accompanying blog post on the HotelTonight Engineering Blog:

HotelTonight

Usage

Installation

If you're not using CocoaPods (or don't know what CocoaPods is), add the following files to your project:

  • HTAutocompleteTextField.m
  • HTAutocompleteTextField.h
  • HTAutocompleteManager.m and HTAutocompleteManager.h

If you're using CocoaPods:

  • Add pod 'HTAutocompleteTextField' to your Podfile
  • Manually add HTAutocompleteManager.m and HTAutocompleteManager.h to your project (these files are not part of the pod, as you will probably want to customize them)

Quickstart Guide

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

HTAutocompleteTextField *textField = [[HTAutocompleteTextField alloc] initWithFrame:CGRectMake(0,0,100,31)];

The data source is the brains of the autocomplete logic. If you just want to autocomplete email addresses, use HTAutocompleteManager from the example project as follows:

textField.autocompleteDataSource = [HTAutocompleteManager sharedManager];
textField.autocompleteType = HTAutocompleteTypeEmail;

Customization

Autocompletion Data Source

HTAutocompleteManager (included in the example project) provides email address autocompletion out of the box. It comes with a list of the top email domains based on the HotelTonight customer database. 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 field (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 fields with different data types. A HTAutocompleteTextFields's data source must implement the following method, as part of the HTAutocompleteDataSource protocol.

- (NSString *)textField:(HTAutocompleteTextField *)textField completionForPrefix:(NSString *)prefix ignoreCase:(BOOL)ignoreCase

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

 [autocompleteTextOffset setDefaultAutocompleteDataSource:[HTAutocompleteManager 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 HTAutocompleteTextField 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 UITextField notifications (i.e. UITextFieldTextDidChangeNotification and friends), you can use [HTAutocompleteTextField 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 @jonsibs, and check out HotelTonight's engineering blog: http://engineering.hoteltonight.com

Also, check out HotelTonight's other iOS open source:

htautocompletetextfield's People

Contributors

abecevello avatar danmartyn avatar hezi avatar jacobjennings avatar jcfalkenberg avatar kav avatar kcoop avatar kgn avatar kmonaghan avatar kylefleming avatar mac-cain13 avatar nielubowicz avatar ryuheechul avatar sgoodwin avatar sibljon avatar wlisac avatar yas375 avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.