How To Change UITexefield Placeholder Colour 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.

Source: iosdevcenters.blogspot.com


Related Posts To How To Change UITexefield Placeholder Colour in Swift 3.0


How To Change UITexefield Placeholder Colour in Swift 3.0 Rating: 4.5 Posted by: oliv7081

Search Here

Popular Posts

Total Pageviews

Recent Posts