BSAutocomplete 0.1.1

BSAutocomplete 0.1.1

BRCountDownView 维护。



BSAutocomplete

CI Status Version License Platform

BSAutocomplete 提供了基于全屏 UI 的简单易用和功能强大的自动补全功能,用于 iOS。
如果您希望以例如 '#'、'@' 或 '$' 这样的前缀开始,无论您喜欢什么前缀,您都可以将自动补全功能添加到 UITextView 或 UITextField 中,以帮助用户在不写任何文字的情况下编写包含前缀的特定内容。

BSAutocomplete 在'All-Dayz'应用程序中被广泛使用。

就像在 'All Dayz' 中一样

就像在这个示例项目中一样

GIF

如何工作的 YouTube 视频链接
a link00
a link01



示例

要运行示例项目,首先克隆仓库,然后从 Example 目录运行 pod install

要求

iOS 10.0+
Swift 4.2 +

如何使用

步骤 0. 导入 BSAutocomplete

import BSAutocomplete

步骤 1. 以程序的方式创建实例作为实例变量
声明并创建以下实例作为实例变量。
BSAutocomplete 仅支持以编程方式实现。

/**
* Creating BSAutocomplete instance..
*/

///
/// - parameter basedOn: a targetView to be based on for which it is usually self.view of UIViewController's instnace. 
/// - parameter prefix: a prefix string to provoke an instance of BSAutocomplete into showing and being hidden. For example, it could be '#', '@' or '$'. 
/// - parameter data: a list of string for you to display, to be shown by an instance of BSAutocomplete.
/// - returns: BSAutocomplete instance

private lazy var autocomplete: BSAutocomplete = { [unowned self] in
  let autocomplete = BSAutocomplete(basedOn: self.view, prefix: Prefix.at.rawValue, data: hashtags)
  autocomplete.delegate = self

  return autocomplete
}()

步骤 1. 声明 BSAutocomplete 的代理以跟踪 BSAutocomplete 在特定情况下提供的各种事件。
您可以通过查看委托方法的命名来假定何时会被调用。

extension ViewController: BSAutocompleteDelegate {
  func autoCompleteDidChooseItem(text: String, sender: Either<UITextView, UITextField>) -> Void {
    print("autoCompleteDidChooseItem : ", text)
  }

  func autoCompleteTextDidChange(text: String, sender: Either<UITextView, UITextField>) -> Void {
    print("autoCompleteTextDidChange : ", text)
  }

  func autoCompleteDidShow(sender: Either<UITextView, UITextField>) -> Void {
    print("autoCompleteDidShow")
  }

  func autoCompleteDidHide(sender: Either<UITextView, UITextField>) -> Void {
    print("autoCompleteDidHide!")
  }
}

步骤 2. 在 viewDidLoad 中,调用 readyToUse() 方法以准备显示 BSAutocomplete。
必须在使用之前完成此操作。请按照以下步骤操作。

override func viewDidLoad() {
  super.viewDidLoad()

  /**
  * Must apply this API in viewDidLoad or similar appropriate method time being called
  * before the use of BSAutocomplete's instance.
  */
  autocomplete.readyToUse()
}

步骤 3. 添加以下代码以跟踪观察当前输入的文本。
应用以下 API 以观察输入的文本。
将输入的最新字符串之一放入 currentUserInput 参数中,并同时提供一个实例,其中包含文本输入正在输入,由库提供的 Either 类型包装,这将 either 是 UITextfield 或 UITextView。
您必须使用此 API。否则,BSAutocomplete 的实例将无法显示。

// MARK: - UITextFieldDelegate Methods -
extension ViewController: UITextFieldDelegate {
  func textField(_ textField: UITextField, shouldChangeCharactersIn range: NSRange, replacementString string: String) -> Bool {
    /**
    * Must apply this API to keep track of the text being written.
    */
    autocomplete.observe(currentUserInput: string, from: .textField(textField))
    
    return true
  }
}

// MARK: - UITextViewDelegate Methods -
extension ViewController: UITextViewDelegate {
func textView(_ textView: UITextView, shouldChangeTextIn range: NSRange, replacementText text: String) -> Bool {
  /**
  * Must apply this API to keep track of the text being written.
  */
  autocomplete.observe(currentUserInput: text, from: .textView(textView))
  
  return true
}



这就全部了!尽情享受 BSAutocomplete!:)

致谢

BSAutocomplete 大量基于 'Ramotion/reel-search' 项目构建,其中 reel-search 为 BSAutocomplete 提供了 Core UI。
(请注意,在 BSAutocomplete 中使用的 reel-search 已经进行了轻度定制,因此如果您想克隆,会有所不同。)

安装

我们建议使用 CocoaPods 安装库。
BSAutocomplete 通过 CocoaPods 提供。要安装它,只需将以下行添加到您的 Podfile 中

pod 'BSAutocomplete'

作者

[email protected]

许可证

BSAutocomplete 在 MIT 许可证下提供。有关更多信息,请参阅 LICENSE 文件。