Coder Social home page Coder Social logo

danielxu / arautocompletetextview Goto Github PK

View Code? Open in Web Editor NEW

This project forked from alexruperez/arautocompletetextview

0.0 1.0 0.0 248 KB

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.

Home Page: http://www.alexruperez.com/repos/21-arautocompletetextview

License: MIT License

arautocompletetextview's Introduction

ARAutocompleteTextView

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:

ARAutocompleteTextView* textField = [[ARAutocompleteTextView 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, #hashtags or @handles, use ARAutocompleteManager from the example project as follows:

textField.autocompleteDataSource = [ARAutocompleteManager sharedManager];
textField.autocompleteType = ARAutocompleteTypeEmail;

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!
  • Ready to work with alexruperez/STTweetLabel.
  • 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

arautocompletetextview's People

Contributors

alexruperez avatar

Watchers

 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.