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

IosUitextfieldUicolor

Ios Problem Overview


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.

Ios Solutions


Solution 1 - Ios

The colour is #C7C7CD (r: 199 g:199 b: 205) (as what pterry26 said)

and the font-family is HelveticaNeue-Medium and size is 16


Note that this is a guess at what the color looks like on a screen. For the actual values, simply inspect the Apple code for attributedPlaceholder.

Solution 2 - Ios

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.

Solution 3 - Ios

I sent a screenshot to my mac and used Photoshop's eyedropper tool. For anyone interested, this is at least a very good approximation of the placeholder color on a white background:

Red: 199, Green: 199, Blue: 205

Solution 4 - Ios

The actual color is not a solid one but has transparency in it. So the closest color is

Red: 4, Green: 4, Blue: 30, Alpha: ~22%

If you use this with a white background you will get what @pterry26 wrote above.

Solution 5 - Ios

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)
}

Solution 6 - Ios

Using the values from the correct answer above

extension UIColor {

    class func greyPlaceholderColor() -> UIColor {
        return UIColor(red: 0.78, green: 0.78, blue: 0.80, alpha: 1.0)
    }

}

Solution 7 - Ios

According to the Apple code, it is 70% gray

open var placeholder: String? // default is nil. string is drawn 70% gray

and if we convert it to rgb :

UIColor.init(red: 178/255, green: 178/255, blue: 178/255, alpha: 1)

Solution 8 - Ios

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.

Solution 9 - Ios

I believe it is R:191 G:191 B:198 A:1. See image below. Here marked controls are UIButton with above Title TextColor and rest are UITextFields with default placeholder color. If iOS makes difference, then this one is iOS 9. enter image description here

Solution 10 - Ios

The code #999999 matches perfectly on my form!

Solution 11 - Ios

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)
  }
}

Solution 12 - Ios

I think you can get the color by use the tools in your Mac.enter image description here

Solution 13 - Ios

Set label font to "light"
mylabel.font = [UIFont fontWithName:@"HelveticaNeue-Light" size:14.0f];
and color code for placeholder text is
#c2b098

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
Questionpterry26View Question on Stackoverflow
Solution 1 - IosDaniel FernandesView Answer on Stackoverflow
Solution 2 - IosBram De GeyterView Answer on Stackoverflow
Solution 3 - Iospterry26View Answer on Stackoverflow
Solution 4 - IosPeter StaevView Answer on Stackoverflow
Solution 5 - IosdanqingView Answer on Stackoverflow
Solution 6 - IosDogCoffeeView Answer on Stackoverflow
Solution 7 - IosAbdulAziz Rustam OgliView Answer on Stackoverflow
Solution 8 - IosAndrey GordeevView Answer on Stackoverflow
Solution 9 - IosVaibhav SaranView Answer on Stackoverflow
Solution 10 - IosEmmaJView Answer on Stackoverflow
Solution 11 - IosRyanMView Answer on Stackoverflow
Solution 12 - IosSemperFiView Answer on Stackoverflow
Solution 13 - Iosharoon jamilView Answer on Stackoverflow