一个 iOS 文本字段,用于表示标签、话题标签和通用令牌。
let tagsField = WSTagsField()
tagsField.layoutMargins = UIEdgeInsets(top: 2, left: 6, bottom: 2, right: 6)
tagsField.contentInset = UIEdgeInsets(top: 10, left: 10, bottom: 10, right: 10)
tagsField.spaceBetweenLines = 5.0
tagsField.spaceBetweenTags = 10.0
tagsField.font = .systemFont(ofSize: 12.0)
tagsField.backgroundColor = .white
tagsField.tintColor = .green
tagsField.textColor = .black
tagsField.fieldTextColor = .blue
tagsField.selectedColor = .black
tagsField.selectedTextColor = .red
tagsField.delimiter = ","
tagsField.isDelimiterVisible = true
tagsField.placeholderColor = .green
tagsField.placeholderAlwaysVisible = true
tagsField.keyboardAppearance = .dark
tagsField.returnKeyType = .next
tagsField.acceptTagOption = .space
tagsField.shouldTokenizeAfterResigningFirstResponder = true
// Events
tagsField.onDidAddTag = { field, tag in
print("DidAddTag", tag.text)
}
tagsField.onDidRemoveTag = { field, tag in
print("DidRemoveTag", tag.text)
}
tagsField.onDidChangeText = { _, text in
print("DidChangeText")
}
tagsField.onDidChangeHeightTo = { _, height in
print("HeightTo", height)
}
tagsField.onValidateTag = { tag, tags in
// custom validations, called before tag is added to tags list
return tag.text != "#" && !tags.contains(where: { $0.text.uppercased() == tag.text.uppercased() })
}
print("List of Tags Strings:", tagsField.tags.map({$0.text}))
要安装它,只需将以下行添加到您的 Cartfile 文件中
github "whitesmith/WSTagsField"
然后运行 carthage update
。
请按照 Carthage 的 README 中的最新说明进行安装。
要安装它,只需将以下行添加到您的 Podfile 文件中
pod "WSTagsField"
然后使用 CocoaPods 1.8.0 或更高版本运行 pod install
。
使用 Xcode 11,只需转到“File” > “Swift Packages” > “Add Package Dependency...” 并使用此仓库: https://github.com/whitesmith/WSTagsField
。
下载所有源文件并将它们放入您的项目中。
最好的贡献方式是提交 pull request。我们会尽力尽快回复您的补丁。如果您发现错误或有疑问,也可以提交一个新的 GitHub issue。
这个项目受到 CLTokenInputView 的启发。