KSTokenView改变背景和charackters

时间:2017-02-24 10:02:12

标签: ios swift kstokenview

我正在使用KSTokenView库,我想要更改ksTokenView的背景颜色,这是我在库中找不到的。在输入。(点)后,它会自动显示为ksToken,我无法将其填写为电子邮件。

这是library

1 个答案:

答案 0 :(得分:1)

检查Programmatically.swift有关更改背景颜色的工作示例。 https://github.com/khawars/KSTokenView/blob/master/Examples/Examples/ViewControllers/Programmatically.swift

您需要更改tokenBackgroundColor对象的KSToken属性。以下是示例链接的示例源代码:

@IBAction func addToken(sender: AnyObject) {
        let title = names[Int(arc4random_uniform(UInt32(names.count)))] as String
        let token = KSToken(title: title, object: title as AnyObject?)

        // Token background color
        var red = CGFloat(Float(arc4random()) / Float(UINT32_MAX))
        var green = CGFloat(Float(arc4random()) / Float(UINT32_MAX))
        var blue = CGFloat(Float(arc4random()) / Float(UINT32_MAX))
        token.tokenBackgroundColor = UIColor(red: red, green: green, blue: blue, alpha: 1.0)

        // Token text color
        red = CGFloat(Float(arc4random()) / Float(UINT32_MAX))
        green = CGFloat(Float(arc4random()) / Float(UINT32_MAX))
        blue = CGFloat(Float(arc4random()) / Float(UINT32_MAX))
        token.tokenTextColor = UIColor(red: red, green: green, blue: blue, alpha: 1.0)

        tokenView.addToken(token)
    }

要避免在键入点(。)时创建令牌,请更改属性tokenizingCharacters。目前,如果您键入点或逗号,它会自动创建令牌。点击这里: https://github.com/khawars/KSTokenView/blob/master/KSTokenView/KSTokenView.swift

 /// 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
   open var tokenizingCharacters = [".", ","]

因此,您可以删除字符以避免创建令牌。像这样:

tokenView.tokenizingCharacters = [];