2017-02-24 64 views
0

我正在使用KSTokenView庫,並且我想更改ksTokenView的背景顏色,我無法在庫上找到它。在輸入。(點)後,它也會自動將其作爲ksToken,我無法將其填充爲電子郵件。KSTokenView更改背景和字符集

這裏是library

+0

如何將KSTokenView庫與pod或add添加到項目中? –

+0

我作爲吊艙添加了 – pmb

回答

1

查看Programmatically.swift瞭解更改背景顏色的示例。 https://github.com/khawars/KSTokenView/blob/master/Examples/Examples/ViewControllers/Programmatically.swift

您需要更改tokenBackgroundColorKSToken對象的屬性。下面是樣本源代碼從上面的例子中的鏈接:

@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 = [];