UITextField中的占位符文本的默认颜色是什么? [英] What's the default color for placeholder text in UITextField?

查看:143
本文介绍了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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆