Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to change UITextfield placeholder color and fontsize using swift 2.0?

Tags:

How to change UITextfield placeholder & fontsize in SWIFT 2.0?

like image 991
Xcode Avatar asked Oct 29 '15 12:10

Xcode


People also ask

How do I change placeholder color in Swift?

You can set the placeholder text using an attributed string. Just pass the color you want to the attributes parameter.

How do I change the placeholder color on a storyboard?

The easiest method to modify the placeholder text color is through the Xcode storyboard interface builder. Select the UITextField of interest and open the identity inspector on the right. Click on the plus symbol in the User Defined Runtime Attributes and add a new row with Key Path as placeholderLabel.

How can I change the color of placeholder of text field?

<input type="text" placeholder="A red placeholder text..">

How can I give placeholder to UITextView in Swift?

Solution #1 - If you want the placeholder to disappear as soon as the user selects the text view: First set the UITextView to contain the placeholder text and set it to a light gray color to mimic the look of a UITextField 's placeholder text. Either do so in the viewDidLoad or upon the text view's creation.


1 Answers

#1. set Placeholder textfield color Programmatically

    var myMutableStringTitle = NSMutableAttributedString()     let Name  = "Enter Title" // PlaceHolderText      myMutableStringTitle = NSMutableAttributedString(string:Name, attributes: [NSFontAttributeName:UIFont(name: "Georgia", size: 20.0)!]) // Font     myMutableStringTitle.addAttribute(NSForegroundColorAttributeName, value: UIColor.redColor(), range:NSRange(location:0,length:Name.characters.count))    // Color     txtTitle.attributedPlaceholder = myMutableStringTitle 

OR

txtTitle.attributedPlaceholder = NSAttributedString(string:"Enter Title", attributes: [NSForegroundColorAttributeName: yellowColor]) 

Note : Name is your placeholder of textField.

PlaceHolder TextFiled :

enter image description here

-------------------------------- OR -------------------------------------

#2. set Placeholder textfield color at runtime attribute

  1. Set textfield placeHolder text Enter Title

    enter image description here

  2. Click on identity inspector of textfield property.

    enter image description here

  3. User Define Runtime Attributes, add color attributes

    Key Path : _placeholderLabel.textColor

    Type : Color

    value : Your Color or RGB value

    enter image description here

    PlaceHolder TextFiled :

    enter image description here

like image 78
Kirit Modi Avatar answered Jan 25 '23 11:01

Kirit Modi