UITextField中的占位符文本的默认颜色是什么? [英] What's the default color for placeholder text in UITextField?
问题描述
有人知道默认情况下UITextField
的占位符文本是什么颜色吗?我正在尝试将UITextView
的文本设置为相同的颜色.我在其他地方已经读到它是UIColor.lightGrayColor()
,但实际上它要轻一些.
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.
推荐答案
您可以通过检查UITextField
中的attributedPlaceholder
来获得此颜色.
You can get this colour from inspecting the attributedPlaceholder
from the UITextField
.
默认值似乎是:NSColor = "UIExtendedSRGBColorSpace 0 0 0.0980392 0.22";
您可以在UIColor
上添加扩展名(或类别):
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年,最新语法仅为:
2018, latest syntax is just:
extension UIColor {
static var officialApplePlaceholderGray: UIColor {
return UIColor(red: 0, green: 0, blue: 0.0980392, alpha: 0.22)
}
}
#colorLiteralRed
已过时.在某些情况下,请注意此.
#colorLiteralRed
was deprecated. Be aware of this in some cases.
这篇关于UITextField中的占位符文本的默认颜色是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!