How To Change UITextfield Placeholder Color in Swift 3.0
Hi. TextField have a placeHolder property to set placeholder. This tutorial for set colour of placeHolder in textField. There are two ways to set textfield placeholder colour. One is programmatically and second one is using runtime attribute.
This tutorial is working on Swift 3.0.
1. textFiled placeholder Programmatically :
var myMutableStringTitle = NSMutableAttributedString()
let Name = "Email ID" // PlaceHolderText
myMutableStringTitle = NSMutableAttributedString(string:Name, attributes: [NSFontAttributeName:UIFont(name: "Georgia", size: 18.0)!]) // Font
myMutableStringTitle.addAttribute(NSForegroundColorAttributeName, value: UIColor.red, range:NSRange(location:0,length:Name.characters.count)) // Color
txtEmailID.attributedPlaceholder = myMutableStringTitle
txtPassword.attributedPlaceholder = NSAttributedString(string:"Password", attributes: [NSForegroundColorAttributeName: UIColor.green])
2. textFiled placeholder runtime attribute:
How To Change UITextfield Placeholder Color in Swift 3.0
Reviewed by KIRIT MODI
on
22:16:00
Rating:
No comments: