iosuitextfielduicolor

What's the default color for placeholder text in UITextField?


Historic question. UIColor.placeholderText now exists.


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.


Solution

  • You can get this colour from inspecting the attributedPlaceholder from the UITextField.

    The default seems to be: NSColor = "UIExtendedSRGBColorSpace 0 0 0.0980392 0.22";

    You could add an extension (or category) on UIColor:

    extension UIColor {
        static var placeholderGray: UIColor {
            return UIColor(colorLiteralRed: 0, green: 0, blue: 0.0980392, alpha: 0.22)
        }
    }
    

    2018, latest syntax is just:

    extension UIColor {
        static var officialApplePlaceholderGray: UIColor {
            return UIColor(red: 0, green: 0, blue: 0.0980392, alpha: 0.22)
        }
    }
    

    #colorLiteralRed was deprecated. Be aware of this in some cases.