Does anyone know what color a UITextField's placeholder text is, by default? I'm trying to set a UITextView's text to the same color. I've read elsewhere that it is UIColor.lightGrayColor() but it is actually a little lighter.
What's the default color for placeholder text in UITextField?
40.1k views Asked by pterry26 At
13
There are 13 answers
0
On
Better to grab the color off of a text field dynamically in case it changes in the future. Default to 70% gray, which is pretty close
extension UITextField {
var placeholderColor: UIColor {
return attributedPlaceholder?.attributes(at: 0, effectiveRange: nil)[.foregroundColor] as? UIColor ?? UIColor(white: 0.7, alpha: 1)
}
}
1
On
Just to add that in iOS 13 (and later), the placeholder color is exposed by Apple via
UIColor.placeholderText
and it's dynamic (supports both dark and light).
Putting it with pre-iOS 13:
static var placeholderText: UIColor {
if #available(iOS 13.0, *) {
return .placeholderText
}
return UIColor(red: 60, green: 60, blue: 67)!.withAlphaComponent(0.3)
}
0
On
Starting from iOS 13 you should use UIColor.placeholderText to make sure the element looks good in both light and dark modes. Documentation:
The color for placeholder text in controls or text views.


You can get this colour from inspecting the
attributedPlaceholderfrom theUITextField.The default seems to be:
NSColor = "UIExtendedSRGBColorSpace 0 0 0.0980392 0.22";You could add an extension (or category) on
UIColor:2018, latest syntax is just:
#colorLiteralRedwas deprecated. Be aware of this in some cases.