72

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.

Sujay
  • 2,510
  • 2
  • 27
  • 47
pterry26
  • 1,230
  • 1
  • 10
  • 20
  • @Fattie, if you convert the values [given by Bram De Geyter's answer](https://stackoverflow.com/a/43346157/3004518) you would see that they convert to `#38000019` (ARGB32) **BUT** if an image editing program you add a white layer with an layer with that color on top, the result would be #FFC7C7CC, which is close to the answers given here ( probably due to rounding when calculating the blue which is `255 * 0.0980392 = 24,999996` ). – auhmaan Aug 02 '18 at 11:28
  • @Fattie Thank you for pointing out that we can see what the color is by looking at the Apple code. I would argue that you could have been significantly more polite when doing so. Your first comment here is also incorrect: they aren't eyeball guesses, they were determined with an eyedropper, and they aren't completely wrong, as I specifically said that my answer was only a good approximation on a white background. I have changed my accepted answer to Bram De Geyter's. Please be a little more thoughtful/considerate when interacting with others on this site. – pterry26 Oct 02 '18 at 16:07
  • hi auhmann, that is simply wrong. the values are right there in the code, and given in the now chosen answer. Software is utterly precise :) – Fattie Oct 02 '18 at 18:23

13 Answers13

109

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.

Fattie
  • 27,874
  • 70
  • 431
  • 719
Daniel Fernandes
  • 1,281
  • 2
  • 10
  • 6
  • @AllenHumphreys I'm afraid the answer is, I believe, simply, Incorrect. it's just the value you see using an eyedropper :) – Fattie Jul 23 '18 at 17:12
  • @Fattie Thanks for providing context for why it's incorrect. That's really all I wanted as it seemed unfair to declare it incorrect with nothing else. – allenh Jul 23 '18 at 18:27
  • 1
    hi @allenh without being rude, it's just completely silly, childish, for **programmers** to "guess at a color". obviously you just **trivially look at the code of Apple, and use that same one line of trivial code**. Anyway! cheers – Fattie Aug 02 '18 at 11:34
  • Hi @Daniel-Fernandes, any idea if there's a way to actually pull from the attributedPlaceholder at runtime, so that it's kept in sync if iOS ever changes its color choice? I tried using `UITextField().attributedPlaceholder?.attribute(NSAttributedString.Key.foregroundColor, at: 0, longestEffectiveRange: nil, in: NSRange(location: 0,length: 0)) as! UIColor`, but that gives a nil pointer error, because the placeholder text isn't set at that stage (it doesn't work if you just set placeholder to = "" first either). – TheNeil Apr 27 '19 at 17:45
45

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.

Fattie
  • 27,874
  • 70
  • 431
  • 719
Bram De Geyter
  • 1,088
  • 8
  • 15
16

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)
}
danqing
  • 3,348
  • 2
  • 27
  • 43
  • For IB users, it's now available in Xcode's color inspector and it's called "Placeholder Text Color". This way it should be backward-compatible. – mojuba Jun 15 '20 at 17:39
12

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

pterry26
  • 1,230
  • 1
  • 10
  • 20
  • The whole point of the question is to know how Apple actually do it programmatically. Obviously it's trivial to look at a screen shot and guess the final flat color. – Fattie Jul 23 '18 at 17:14
  • @Fattie, While I agree that it's more useful to know how it's done programmatically, I'm the one who asked the question and doing this solved my problem, thus addressing the "whole point of the question". – pterry26 Oct 02 '18 at 16:02
12

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.

Community
  • 1
  • 1
Peter Staev
  • 1,119
  • 7
  • 12
6

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

}
DogCoffee
  • 19,820
  • 10
  • 87
  • 120
  • 2
    You can also just do `...red: 199/255, green 199/255, blue 205/255...` to make it more obvious – Tommy K Sep 21 '16 at 18:10
  • The whole point of the question is to know how Apple actually do it programmatically. Obviously it's trivial to look at a screen shot and guess the final flat color. – Fattie Jul 23 '18 at 17:14
3

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)
georgeawg
  • 48,608
  • 13
  • 72
  • 95
2

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.

Andrey Gordeev
  • 30,606
  • 13
  • 135
  • 162
0

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

Vaibhav Saran
  • 12,848
  • 3
  • 65
  • 75
0

The code #999999 matches perfectly on my form!

EmmaJ
  • 35
  • 10
0

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)
  }
}
RyanM
  • 4,474
  • 4
  • 37
  • 44
-2

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

SemperFi
  • 15
  • 5
-2

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