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

OR 

txtPassword.attributedPlaceholder = NSAttributedString(string:"Password", attributes: [NSForegroundColorAttributeName: UIColor.green])

2. textFiled placeholder runtime attribute:  

1. Set textFiled placeholder text : Confirm Password




2. Select identity inspector on textfield property. and set userDefine runtime attribute of placeholder colour.



Key Path : _placeholderLabel.textColor


Type         : Color

Value       : _Color or RGB value.


OutPut :


Thanks.

How To Change UITextfield Placeholder Color in Swift 3.0 How To Change UITextfield Placeholder Color in Swift 3.0 Reviewed by KIRIT MODI on 22:16:00 Rating: 5

No comments:

Powered by Blogger.