DPTagDetectionTextView
从 Textview 进行标签检测。
使用 CocoaPods 进行安装
CocoaPods 是一个 Objective-C 的依赖管理器。您可以使用以下命令安装它
$ gem install cocoapods
Podfile
要使用 CocoaPods 将 DPTagDetectionTextView 集成到您的 Xcode 项目中,请在您的 Podfile
中指定它
source 'https://github.com/CocoaPods/Specs.git'
platform :ios, '8.0'
target 'TargetName' do
use_frameworks!
pod 'DPTagDetectionTextView'
end
然后,运行以下命令
$ pod install
手动安装
下载项目并将 DPTagTextView.swift
文件粘贴到您的项目中
如何使用
代码
配置
self.txtMain.dpTagDelegate = self // set DPTagTextViewDelegate Delegate
self.txtMain.tagPrefix = "@[---" // or use Interface Builder
self.txtMain.tagPostfix = "---]" // or use Interface Builder
self.txtMain.setTagDetection(true) // true :- detecte tag on tap , false :- Search Tags using @,#,etc.
self.txtMain.arrSearchWith = ["@","#","$$"] // Search start with this strings.
let arrTags = self.txtMain.getAllTag("hello @[---Datt---]") // get all tags from string.
self.txtMain.txtFont = UIFont(name: "HelveticaNeue", size: CGFloat(15))! // set textview text font family
self.txtMain.tagFont = UIFont(name: "HelveticaNeue-Bold", size: CGFloat(17.0))! // set textview tag font family
var arrTags = [DPTag]()
for i in 0 ..< arrTagedUser.count { // arrTagedUser = ["Datt"]
arrTags.append(DPTag(strTagName: arrTagedUser[i], tagID: i))
}
self.txtMain.setTxtAndTag(str: "hello @[---Datt---]", tags: arrTags)
self.txtMain.setTxt("hello @[---Datt---]")
委托方法
extension ViewController : DPTagTextViewDelegate {
func tagSearchString(_ str: String) {
}
func removeTag(at index: Int, tag: DPTag) {
}
func insertTag(at index: Int, tag: DPTag) {
}
func detectTag(at index: Int, tag: DPTag) {
}
}