Changing UITextField Placeholder font
Objective-C:
UIColor *color = [UIColor blackColor]; someUITextField.attributedPlaceholder = [[NSAttributedString alloc] initWithString:@"Placeholder Text" attributes:@{ NSForegroundColorAttributeName: color, NSFontAttributeName : [UIFont fontWithName:@"Roboto-Bold" size:17.0] } ];
(There are no brackets between literal dictionary
key-value pairs.)
Swift:
let attributes = [ NSForegroundColorAttributeName: UIColor.blackColor(), NSFontAttributeName : UIFont(name: "Roboto-Bold", size: 17)! // Note the !]someUITextField.attributedPlaceholder = NSAttributedString(string: "Placeholder Text", attributes:attributes)
Update for Swift 4.x:
textField.attributedPlaceholder = NSAttributedString(string: "Placeholder Text", attributes: [ .foregroundColor: UIColor.lightGray, .font: UIFont.boldSystemFont(ofSize: 14.0)])
For the convenience of swift people:
someTextField.attributedPlaceholder = NSAttributedString(string: "someString", attributes:[NSForegroundColorAttributeName: UIColor.lightGrayColor(), NSFontAttributeName: PlaceHolderFont])