[Swift]UITextFieldのクリアボタンの色を変える

UITextFieldのクリアボタンの色を変える

extension UITextField {
    func setTintColorToClearButton(){
        let anyobj:AnyObject? = self.valueForKey("_clearButton")
        if let anyobj:AnyObject = anyobj {
            if anyobj.isMemberOfClass(UIButton) {
                let button:UIButton = anyobj as UIButton
                if let image:UIImage = button.imageForState(.Highlighted) {
                    let paintedImage:UIImage = image.imageWithRenderingMode(UIImageRenderingMode.AlwaysTemplate)
                    button.setImage(paintedImage, forState: .Normal)
                    button.setImage(paintedImage, forState: .Highlighted)
                }
            }
        }
    }
}

self.textField.tintColor = UIColor.whiteColor()
self.textField.setTintColorToClearButton()

before
textfield1

after
textfield2