• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

LaurentiuUngur/LUAutocompleteView: Highly configurable autocomplete view that is ...

原作者: [db:作者] 来自: 网络 收藏 邀请

开源软件名称(OpenSource Name):

LaurentiuUngur/LUAutocompleteView

开源软件地址(OpenSource Url):

https://github.com/LaurentiuUngur/LUAutocompleteView

开源编程语言(OpenSource Language):

Swift 90.9%

开源软件介绍(OpenSource Introduction):

LUAutocompleteView

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

Build Status Swift 5 Carthage compatible 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.7.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, '9.0'
use_frameworks!

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

Then, run the following command:

$ pod install

Carthage

You can use Carthage to install LUAutocompleteView by adding it to your Cartfile:

github "LaurentiuUngur/LUAutocompleteView" ~> 4.0

Then run carthage update.

If this is your first time using Carthage in the project, you'll need to go through some additional steps as explained over at Carthage.

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", majorVersion: 4)

Here's an example of PackageDescription:

import PackageDescription

let package = Package(name: "MyApp",
    dependencies: [
        .Package(url: "https://github.com/LaurentiuUngur/LUAutocompleteView", majorVersion: 4)
    ])

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
  • 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 10.2+
  • Swift 5.0+
  • iOS 9.0+

Author

License

  • LUAutocompleteView is available under the MIT license.



鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
torch/qtlua: Lua interface to QT library发布时间:2022-08-16
下一篇:
orts/server: A real map datapack based on TFS 1.2 engine发布时间:2022-08-16
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap