GithubHelp home page GithubHelp logo

beujator / autocompletetextfieldswift Goto Github PK

View Code? Open in Web Editor NEW

This project forked from mnbayan/autocompletetextfieldswift

0.0 2.0 0.0 576 KB

Simple and straightforward sublass of UITextfield to manage string suggestions

License: MIT License

Swift 100.00%

autocompletetextfieldswift's Introduction

AutocompleteTextfieldSwift

Simple and straightforward sublass of UITextfield to manage string suggestions

Plain Attributed
Plain Attributed

Installation

Drag AutoCompleteTextField Folder in your project

How to use

Customize

Customize autocomplete suggestions! You can override the provided properties to create your desired appearance. Properties are pretty self explanatory. Some of them are listed below, with their respective default values:

/// Font for the text suggestions
public var autoCompleteTextFont = UIFont(name: "HelveticaNeue-Light", size: 12)
/// When set to true, shows autocomplete text with formatting
public var enableAttributedText = false
/// User Defined Attributes
public var autoCompleteAttributes:[String:AnyObject]?
/// Hides autocomplete tableview after selecting a suggestion
public var hidesWhenSelected = true

Setting Content

The most important property to use is the autoCompleteStrings. As what is declared in the description setting the value of this will automatically reload the tableview, through the use of didSet

/// The strings to be shown on as suggestions, setting the value of this automatically reload the tableview
public var autoCompleteStrings:[String]?{
   didSet{ reload() }
}

User Interactions

To handle text changed event, use onTextChange: closure. This returns the current text content of the textfield.

autocompleteTextfield.onTextChange = {[weak self] text in 
// your code goes here
...
}

To know when user selected a text, use onSelect: closure: This returns the selected text and it's indexPath.

autocompleteTextfield.onSelect = {[weak self] text, indexpath in
// your code goes here
...
}

It's that easy! Feel free to use it, don't worry, it's free. :)

Example Code:

In the example project, I used Google Places Autocomplete API to show the usage of this library. For testing purposes i created my own google api key.

If you want to create your own Google Api Key follow the steps in this link

Note: Recent updates in google places API requires you to enable "Google Places API Web Service" and use a Server Key instead of an iOS key. To do so, go to Google Developers Console.

License

AutocompleteTextfield is under MIT license. See LICENSE for details.

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.