Giter Site home page Giter Site logo

laurentiuungur / luautocompleteview Goto Github PK

View Code? Open in Web Editor NEW
53.0 4.0 22.0 792 KB

Highly configurable autocomplete view that is attachable to any UITextField

License: MIT License

Ruby 5.30% Swift 94.70%
cocoapods pods swift ios autocomplete autocomplete-search xcode cocoa cocoa-touch carthage

luautocompleteview's Introduction

LUAutocompleteView

Easy to use and highly configurable autocomplete view that is attachable to any UITextField

Swift 5 Swift Package Manager compatible Pod Version Pod Platform Pod License

Installation

CocoaPods

CocoaPods is a dependency manager for Cocoa projects. You can install it with the following command:

$ sudo gem install cocoapods

CocoaPods 1.13.0+ is required.

To integrate LUAutocompleteView into your Xcode project using CocoaPods, specify it in your Podfile:

source 'https://github.com/CocoaPods/Specs.git'
platform :ios, '13.0'
use_frameworks!

target '<Your Target Name>' do
    pod 'LUAutocompleteView'
end

Then, run the following command:

$ pod install

Swift Package Manager

To integrate using Apple's Swift Package Manager, add the following as a dependency to your Package.swift:

.package(url: "https://github.com/LaurentiuUngur/LUAutocompleteView", from: Version(5, 0, 0))

Manually

If you prefer not to use either of the before mentioned dependency managers, you can integrate LUAutocompleteView into your project manually.

Usage

  • Import LUAutocompleteView into your project.
import LUAutocompleteView
  • Add autocomplete view as subview
view.addSubview(autocompleteView)
  • Assign to textField property the text field to which the autocomplete view you want be attached.
autocompleteView.textField = textField
  • Set as data source and delegate.
autocompleteView.dataSource = self
autocompleteView.delegate = self
  • Implement LUAutocompleteViewDataSource and LUAutocompleteViewDelegate protocols.
// MARK: - LUAutocompleteViewDataSource

extension ViewController: LUAutocompleteViewDataSource {
    func autocompleteView(_ autocompleteView: LUAutocompleteView, elementsFor text: String, completion: @escaping ([String]) -> Void) {
        let elementsThatMatchInput = elements.filter { $0.lowercased().contains(text.lowercased()) }
        completion(elementsThatMatchInput)
    }
}

// MARK: - LUAutocompleteViewDelegate

extension ViewController: LUAutocompleteViewDelegate {
    func autocompleteView(_ autocompleteView: LUAutocompleteView, didSelect text: String) {
        print(text + " was selected from autocomplete view")
    }
}

Customisation

  • Create your custom autocomplete cell by subclassing LUAutocompleteTableViewCell.
  • Override func set(text: String) from LUAutocompleteTableViewCell that is called every time when given text should be displayed by the cell.
import UIKit
import LUAutocompleteView

final class CustomAutocompleteTableViewCell: LUAutocompleteTableViewCell {
    // MARK: - Base Class Overrides

    override func set(text: String) {
        textLabel?.text = text
        textLabel?.textColor = .red
    }
}
  • Assign to autocompleteCell property your custom autocomplete cell.
autocompleteView.autocompleteCell = CustomAutocompleteTableViewCell.self

For more usage details please see example app

Requirements

  • Xcode 15.0+
  • Swift 5.9+
  • iOS 13.0+

Author

License

  • LUAutocompleteView is available under the MIT license.

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.