How to change UITextfield
placeholder
& fontsize
in SWIFT 2.0?
You can set the placeholder text using an attributed string. Just pass the color you want to the attributes parameter.
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.
<input type="text" placeholder="A red placeholder text..">
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. 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 :
-------------------------------- OR -------------------------------------
#2. set Placeholder textfield color at runtime attribute
Set textfield placeHolder text Enter Title
Click on identity inspector of textfield property.
User Define Runtime Attributes, add color attributes
Key Path : _placeholderLabel.textColor
Type : Color
value : Your Color or RGB value
PlaceHolder TextFiled :
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With