How to dynamically change placeholder color of the UITextField
?
This is always the same system color.
No option in xib editor.
First add this extension
extension UITextField{
@IBInspectable var placeHolderTextColor: UIColor? {
set {
let placeholderText = self.placeholder != nil ? self.placeholder! : ""
attributedPlaceholder = NSAttributedString(string:placeholderText, attributes:[NSForegroundColorAttributeName: newValue!])
}
get{
return self.placeHolderTextColor
}
}
}
Then you can change placeholder text color via storyboard or by just setting it like this :
textfield.placeHolderTextColor = UIColor.red