All Projects → apasccon → Searchtextfield

apasccon / Searchtextfield

Licence: mit
UITextField subclass with autocompletion suggestions list

Programming Languages

swift
15916 projects

Projects that are alternatives of or similar to Searchtextfield

react-native-autocomplete-dropdown
Dropdown Item picker with search and autocomplete (typeahead) functionality for react native
Stars: ✭ 87 (-91.12%)
Mutual labels:  autocomplete, dropdown
elm-selectize
selectize-like dropdown menu with autocompletion in elm
Stars: ✭ 28 (-97.14%)
Mutual labels:  autocomplete, dropdown
choc-autocomplete
🏇 Autocomplete Component Package for Chakra UI
Stars: ✭ 286 (-70.82%)
Mutual labels:  autocomplete, dropdown
React Selectrix
A beautiful, materialized and flexible React Select control
Stars: ✭ 166 (-83.06%)
Mutual labels:  autocomplete, dropdown
vue-single-select
single select dropdown with autocomplete
Stars: ✭ 43 (-95.61%)
Mutual labels:  autocomplete, dropdown
Ng Select
⭐ Native angular select component
Stars: ✭ 2,781 (+183.78%)
Mutual labels:  autocomplete, dropdown
revodropdown
Minimalistic dropdown and auto-complete component with filtering and keyboard support
Stars: ✭ 20 (-97.96%)
Mutual labels:  autocomplete, dropdown
Multiselect
Vue 3 multiselect component with single select, multiselect and tagging options.
Stars: ✭ 92 (-90.61%)
Mutual labels:  autocomplete, dropdown
frontal
An Angular select/dropdown component
Stars: ✭ 20 (-97.96%)
Mutual labels:  autocomplete, dropdown
react-native-dropdown-autocomplete
Autocomplete input with dropdown modal component for React native. Useful for pages with multiple autocomplete's.
Stars: ✭ 97 (-90.1%)
Mutual labels:  autocomplete, dropdown
Smartmaterialspinner
The powerful android spinner library for your application
Stars: ✭ 108 (-88.98%)
Mutual labels:  autocomplete, dropdown
Autocomplete.js
Simple autocomplete pure vanilla Javascript library.
Stars: ✭ 3,428 (+249.8%)
Mutual labels:  autocomplete, dropdown
React Input Enhancements
Set of enhancements for input control
Stars: ✭ 1,375 (+40.31%)
Mutual labels:  autocomplete, dropdown
Autocomplete
Blazing fast and lightweight autocomplete widget without dependencies. Only 1KB gzipped. Demo:
Stars: ✭ 244 (-75.1%)
Mutual labels:  autocomplete, dropdown
Downshift
🏎 A set of primitives to build simple, flexible, WAI-ARIA compliant React autocomplete, combobox or select dropdown components.
Stars: ✭ 10,183 (+939.08%)
Mutual labels:  autocomplete, dropdown
hv-autocomplete
Fast and flexible autocomplete library
Stars: ✭ 16 (-98.37%)
Mutual labels:  autocomplete, dropdown
Core Components
Accessible and lightweight Javascript components
Stars: ✭ 85 (-91.33%)
Mutual labels:  autocomplete, dropdown
Autocomplete
🔮 Fast and full-featured autocomplete library
Stars: ✭ 1,268 (+29.39%)
Mutual labels:  autocomplete, dropdown
Autocomplete
jQuery like auto complete for iOS UITextField
Stars: ✭ 36 (-96.33%)
Mutual labels:  autocomplete, uitextfield
Material Ui Superselectfield
multiselection autocomplete dropdown component for Material-UI
Stars: ✭ 260 (-73.47%)
Mutual labels:  autocomplete, dropdown

alt_tag

SearchTextField

Version License Platform

Overview

SearchTextField is a subclass of UITextField, written in Swift that makes really easy the ability to show an autocomplete suggestions list.
You can decide wether to show the list as soon as the field is focused or when the user starts typing.
You can also detects when the user stops typing, very useful when you can get a suggestion list from a remote server.

New Feature! Now you can make suggestions "inline", showing the first matched result as the placeholder (instead of the results list) and selecting it when the user touches the enter key.


alt_tag

Requirements

  • iOS 9

Installation

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

use_frameworks!

pod "SearchTextField"

Manual installation

Just import SearchTextField.swift into your project

Usage

You can use it in the simplest way...

import SearchTextField

// Connect your IBOutlet...
@IBOutlet weak var mySearchTextField: SearchTextField!

// ...or create it manually
let mySearchTextField = SearchTextField(frame: CGRectMake(10, 100, 200, 40))

// Set the array of strings you want to suggest
mySearchTextField.filterStrings(["Red", "Blue", "Yellow"])

...or you can customize it as you want

// Show also a subtitle and an image for each suggestion:

let item1 = SearchTextFieldItem(title: "Blue", subtitle: "Color", image: UIImage(named: "icon_blue"))
let item2 = SearchTextFieldItem(title: "Red", subtitle: "Color", image: UIImage(named: "icon_red"))
let item3 = SearchTextFieldItem(title: "Yellow", subtitle: "Color", image: UIImage(named: "icon_yellow"))
mySearchTextField.filterItems([item1, item2, item3])

// Set a visual theme (SearchTextFieldTheme). By default it's the light theme
mySearchTextField.theme = SearchTextFieldTheme.darkTheme()

// Modify current theme properties
mySearchTextField.theme.font = UIFont.systemFontOfSize(12)
mySearchTextField.theme.bgColor = UIColor (red: 0.9, green: 0.9, blue: 0.9, alpha: 0.3)
mySearchTextField.theme.borderColor = UIColor (red: 0.9, green: 0.9, blue: 0.9, alpha: 1)
mySearchTextField.theme.separatorColor = UIColor (red: 0.9, green: 0.9, blue: 0.9, alpha: 0.5)
mySearchTextField.theme.cellHeight = 50

// Set specific comparision options - Default: .caseInsensitive
mySearchTextField.comparisonOptions = [.caseInsensitive]

// Set the max number of results. By default it's not limited
mySearchTextField.maxNumberOfResults = 5

// You can also limit the max height of the results list
mySearchTextField.maxResultsListHeight = 200

// Customize the way it highlights the search string. By default it bolds the string
mySearchTextField.highlightAttributes = [NSBackgroundColorAttributeName: UIColor.yellowColor(), NSFontAttributeName:UIFont.boldSystemFontOfSize(12)]

// Handle what happens when the user picks an item. By default the title is set to the text field
mySearchTextField.itemSelectionHandler = {item, itemPosition in
    mySearchTextField.text = item.title
}

// You can force the results list to support RTL languages - Default: false
mySearchTextField.forceRightToLeft = true

// Show the list of results as soon as the user makes focus - Default: false
mySearchTextField.startVisible = true

// ...or show the list of results even without user's interaction as soon as created - Default: false
mySearchTextField.startVisibleWithoutInteraction = true

// Start filtering after an specific number of characters - Default: 0
mySearchTextField.minCharactersNumberToStartFiltering = 3

// Force to show the results list without filtering (but highlighting)
mySearchTextField.forceNoFiltering = true

// Explicitly hide the results list
mySearchTextField.hideResultsList()

/**
* Update data source when the user stops typing.
* It's useful when you want to retrieve results from a remote server while typing
* (but only when the user stops doing it)
**/
mySearchTextField.userStoppedTypingHandler = {
    if let criteria = self.mySearchTextField.text {
        if criteria.characters.count > 1 {

            // Show the loading indicator
            self.mySearchTextField.showLoadingIndicator()

            self.searchMoreItemsInBackground(criteria) { results in
                // Set new items to filter
                self.mySearchTextField.filterItems(results)

                // Hide loading indicator
                self.mySearchTextField.stopLoadingIndicator()
            }
        }
    }
}

// Handle item selection - Default behaviour: item title set to the text field
mySearchTextField.itemSelectionHandler = { filteredResults, itemPosition in
    // Just in case you need the item position
    let item = filteredResults[itemPosition]
    print("Item at position \(itemPosition): \(item.title)")

    // Do whatever you want with the picked item
    self.mySearchTextField.text = item.title
}

// Define a results list header - Default: nothing
let header = UILabel(frame: CGRect(x: 0, y: 0, width: acronymTextField.frame.width, height: 30))
header.backgroundColor = UIColor.lightGray.withAlphaComponent(0.3)
header.textAlignment = .center
header.font = UIFont.systemFont(ofSize: 14)
header.text = "Pick your option"
mySearchTextField.resultsListHeader = header



New feature: show the first matched result as placeholder (inline mode)

// Set the array of strings you want to suggest
mySearchTextField.filterStrings(["Red", "Blue", "Yellow"])

// Then set the inline mode in true
mySearchTextField.inlineMode = true

New feature: autocomplete from, for example, a list of email domains

emailInlineTextField.inlineMode = true
emailInlineTextField.startFilteringAfter = "@"
emailInlineTextField.startSuggestingInmediately = true
emailInlineTextField.filterStrings(["gmail.com", "yahoo.com", "yahoo.com.ar"])

Swift Versions

Swift 5 supported from 1.2.3 version.

Swift 4 supported from 1.2.0 version.

Install v1.0.0 if you need to support Swift 2.3.

Install v1.0.2 and above if you want to support Swift 3.

Demo

Check out the Example project.

Author

Alejandro Pasccon, [email protected]

License

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

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].