测试已测试 | ✗ |
语言语言 | SwiftSwift |
许可证 | MIT |
发布上次发布 | 2017年11月 |
SwiftSwift 版本 | 4.0 |
SPM支持 SPM | ✗ |
由 Khawar Shahzad 维护。
KSTokenView 是一种控件,它在一个可编辑的 UITextField 中显示一系列标记,并向代理对象发送消息。它还可以用于从用户处接收文本并异步执行搜索操作。UI 可以完全自定义,以看起来像是应用程序的一部分。
点击 此处 进行实时预览。
在您的 Podfile 中为 KSTokenView
添加 pod 条目
source 'https://github.com/CocoaPods/Specs.git'
platform :ios, '9.0'
use_frameworks!
target '<Your Target Name>' do
pod 'KSTokenView', '~> 4.0'
end
然后,运行以下命令
$ pod install
或者,您可以直接将 KSTokenView
目录下的所有源文件直接添加到您的项目中。
KSTokenView
目录到您的项目中。如果您在项目外提取了代码存档,请确保选择“复制项”。UIView
拖放到您的 View
中。身份检查器
中,设置自定义类 KSTokenView
。 outlets
。tokenView.delegate = self
tokenView.promptText = "Top 5: "
tokenView.placeholder = "Type to search"
tokenView.descriptionText = "Languages"
tokenView.maxTokenLimit = 5 //default is -1 for unlimited number of tokens
tokenView.style = .Squared`
编程方式创建 KSTokenView
对象并将其作为 Subview
添加。
let tokenView = KSTokenView(frame: CGRect(x: 10, y: 50, width: 300, height: 40))
tokenView.delegate = self
tokenView.promptText = "Top 5: "
tokenView.placeholder = "Type to search"
tokenView.descriptionText = "Languages"
tokenView.maxTokenLimit = 5
tokenView.style = .Squared
view.addSubview(tokenView)
按照以下方式自定义 KSTokenView
的外观
/// default is true. token can be deleted with keyboard 'x' button
tokenView.shouldDeleteTokenOnBackspace = true
/// Only works for iPhone now, not iPad devices. default is false. If true, search results are hidden when one of them is selected
tokenView.shouldHideSearchResultsOnSelect = false
/// default is false. If true, already added token still appears in search results
tokenView.shouldDisplayAlreadyTokenized = false
/// default is ture. Sorts the search results alphabatically according to title provided by tokenView(_:displayTitleForObject) delegate
tokenView.shouldSortResultsAlphabatically = true
/// default is true. If false, token can only be added from picking search results. All the text input would be ignored
tokenView.shouldAddTokenFromTextInput = true
/// default is 1
tokenView.minimumCharactersToSearch = 1
/// Default is (TokenViewWidth, 200)
tokenView.searchResultSize = CGSize(width: tokenView.frame.width, height: 120)
/// Default is whiteColor()
tokenView.searchResultBackgroundColor = UIColor.whiteColor()
/// default is UIColor.blueColor()
tokenView.activityIndicatorColor = UIColor.blueColor()
/// default is 120.0. After maximum limit is reached, tokens starts scrolling vertically
tokenView.maximumHeight = 120.0
/// default is UIColor.grayColor()
tokenView.cursorColor = UIColor.grayColor()
/// default is 10.0. Horizontal padding of title
tokenView.paddingX = 10.0
/// default is 2.0. Vertical padding of title
tokenView.paddingY = 2.0
/// default is 5.0. Horizontal margin between tokens
tokenView.marginX = 5.0
/// default is 5.0. Vertical margin between tokens
tokenView.marginY = 5.0
/// default is UIFont.systemFontOfSize(16)
tokenView.font = UIFont.systemFontOfSize(16)
/// default is 50.0. Caret moves to new line if input width is less than this value
tokenView.minWidthForInput = 100.0
/// default is ", ". Used to seperate titles when untoknized
tokenView.seperatorText = ", "
/// default is 0.25.
tokenView.animateDuration = 0.25
/// default is true. When resignFirstResponder is called tokens are removed and description is displayed.
tokenView.removesTokensOnEndEditing = true
/// Default is "selections"
tokenView.descriptionText = "Languages"
/// set -1 for unlimited.
tokenView.maxTokenLimit = 5
/// default is "To: "
tokenView.promptText = "Top 5: "
/// default is true. If false, cannot be edited
tokenView.editable = true
/// default is nil
tokenView.placeholder = "Type to search"
/// default is .Rounded, creates rounded corner
tokenView.style = .Squared
/// default is .Vertical, following creates horizontal scrolling direction
tokenView.direction = .Horizontal
/// An array of string values. Default values are "." and ",". Token is created with typed text, when user press any of the character mentioned in this Array
tokenView.tokenizingCharacters = [","]
请参阅示例项目以获取详细信息。
此代码根据 MIT 许可证条款和条件进行分发。