You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Swift中UITextField默认占位符颜色查询:求RGB/HEX值

UITextField默认占位符颜色的RGB/HEX值

Great question! The default placeholder color for UITextField isn't a fixed hardcoded value across all iOS versions and appearance modes (light/dark), but here's the breakdown of the standard values you'll encounter:

  • Light Mode (iOS 13+): The typical HEX value is #999999 (RGB: 153, 153, 153). This corresponds to the system's dynamic placeholderText color in light appearance.
  • Dark Mode (iOS 13+): The standard HEX value shifts to #666666 (RGB: 102, 102, 102), matching the dark appearance variant of the same system color.

If you want to get the exact current system value for your target iOS version, you can fetch it programmatically instead of relying on hardcoded numbers. Here's how:

Swift Code

let sampleTextField = UITextField()
if let placeholderColor = sampleTextField.placeholderLabel?.textColor {
    guard let components = placeholderColor.cgColor.components else { return }
    let red = Int(components[0] * 255)
    let green = Int(components[1] * 255)
    let blue = Int(components[2] * 255)
    print("Placeholder RGB: (\(red), \(green), \(blue))")
}

Objective-C Code

UITextField *sampleTextField = [[UITextField alloc] init];
UIColor *placeholderColor = sampleTextField.placeholderLabel.textColor;
CGFloat red, green, blue;
[placeholderColor getRed:&red green:&green blue:&blue alpha:nil];
NSLog(@"Placeholder RGB: (%d, %d, %d)", (int)(red * 255), (int)(green * 255), (int)(blue * 255));

A quick pro tip: If you're building custom UI elements with placeholder labels, avoid hardcoding these RGB/HEX values. Instead, use the system's built-in color:

  • Swift: UIColor.placeholderText
  • Objective-C: [UIColor placeholderTextColor]

This ensures your custom placeholders automatically adapt to light/dark mode and any future system design changes, which is far more robust than using fixed colors.

内容的提问来源于stack exchange,提问作者Evgeniy Kleban

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.28 04:01:56