GithubHelp home page GithubHelp logo

ozzie00 / cltokeninputview Goto Github PK

View Code? Open in Web Editor NEW

This project forked from rsattar/cltokeninputview

0.0 3.0 0.0 274 KB

A replica of iOS's native contact bubbles UI

License: MIT License

Ruby 13.92% Objective-C 86.08%

cltokeninputview's Introduction

CLTokenInputView

Image Screencap GFY

About

CLTokenInputView is an almost pixel perfect replica of the input portion iOS's native contacts picker, used in Mail.app and Messages.app when composing a new message.

Check out the sample view controller which uses CLTokenInputView to see how to incorporate it into your UI. We use this in our apps at Cluster Labs, Inc..

Note

It does not provide the autocomplete drop down and matching; you must provide that yourself, so that CLTokenInputView can remain very generic and flexible. You can copy what the sample app is doing to show an autocompleting table view and maintain a list of the selected "tokens".

Usage

To run the example project, clone the repo, and open the Xcode project. You should use this on iOS 7 and up.

To use this in your code, you should add an instance of CLTokenInputView to your view hierarchy. Typically it should be anchored to the top of your UI and to the sides. Using Autolayout CLTokenInputView can grow by itself, but if you need to control it manually, you can use the delegate.

You should implement:

- (void)tokenInputView:(CLTokenInputView *)view didChangeText:(NSString *)text 
{
	// Update your autocompletion table results with the text
}

When the user taps on one of your autocomplete items, you should call: -addToken: on token input view. Example:

NSString *name = self.filteredNames[indexPath.row];
CLToken *token = [[CLToken alloc] initWithDisplayText:name context:nil];
[self.tokenInputView addToken:token];

Be sure to listen for:

- (void)tokenInputView:(CLTokenInputView *)view didAddToken:(CLToken *)token;
- (void)tokenInputView:(CLTokenInputView *)view didRemoveToken:(CLToken *)token;

...and update your local data model of selected items.

Lastly, you can implement:

- (CLToken *)tokenInputView:(CLTokenInputView *)view tokenForText:(NSString *)text 
{
	// Return a CLToken instance that matches the text that has been entered.
	// Return nil if nothing matches
}

... so that a user can typically select the first result in your autocomplete.

Customization

CLTokenInputView is customizable using:

  • tintColor — Adjust the selection and text colors.
  • fieldView — (Optional) View to show to the top left of the tokens.
  • fieldName — (Optional, but recommended) Text to show before the token list (e.g. "To:")
  • placeholderText — (Optional, but recommended) Text to show as a hint for the text field.
  • accessoryView — (Optional) View to show on the top right. (Often to launch a contact picker, like in Mail.app).
  • keyboardType — Adjust the keyboard type (UIKeyboardType).
  • autocapitalizationType — Adjust the capitalization behavior (UITextAutocapitalizationType).
  • autocorrectionType — Adjust the autocorrection behavior (UITextAutocorrectionType).
  • drawBottomBorder — Set to YES if CLTokenInputView should draw a native-style border below itself.

Things I'd Like To Do:

  • Build the "collapsed" mode like in Mail.app which replaces the token UI with "[first-item] and N more"
  • Call search about 150ms after pausing typing
  • Scroll text field into position after typing
  • (Maybe?) Look into adding a very generic, flexible autocomplete UI?

Installation

CLTokenInputView is available through CocoaPods. To install it, simply add the following line to your Podfile:

pod "CLTokenInputView"

Or, you can take all the .h and .m files from CLTokenInputView/CLTokenInputView.

Author

Cluster Labs, Inc., [email protected]

License

CLTokenInputView is available under the MIT license. See the LICENSE file for more info.

cltokeninputview's People

Contributors

rsattar avatar

Watchers

Oz avatar James Cloos 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.