whichappMHdetector
示例
要运行示例项目,请克隆仓库,并在 Example 目录下首先运行 pod install
。
描述
whichappMHdetector 可以在您键入时检测到 @
和 #
,甚至在您将光标移回到提及或标签词区域内时,然后您可以编辑它。
用法
1- 导入 whichappMHdetector
import UIKit
import whichappMHdetector
2- 创建 mentionHashtagDetector 的实例并设置代理
//Making instance
let mentionHashtag = mentionHashtagDetector()
override func viewDidLoad() {
super.viewDidLoad()
///Setting Delegates:
//UITextView Delegate
textView.delegate = self
//mentionHashtagDetector Delegate
mentionHashtag.delegate = self
}
3- 每次文本更改时调用 detectSign 函数,只需在 textViewDidChange
下调用此函数即可
extension ViewController:UITextViewDelegate {
func textViewDidChange(_ textView: UITextView) {
///send every change in UITextView to the mentionHashtagDetector
mentionHashtag.detectSign(textView: textView)
}
}
4- 监听 mentionHashtagDetectorDelegate
///Response of mentionHashtagDetector
extension ViewController:mentionHashtagDetectorDelegate {
func didSignDetected(_ text: String, _ signType: signTypeModels) {
//Print("\(text) Type=> \(signType)")
}
}
5- 完成 :)
安装
whichappMHdetector 通过 CocoaPods 提供。要安装,只需将以下行添加到您的 Podfile 中
pod 'whichappMHdetector'
作者
sajjadsarkoobi, [email protected]
许可证
whichappMHdetector 在 MIT 许可证下可用。有关更多信息,请参阅 LICENSE 文件。