iOS UITextField Placeholder 颜色设置教程
在 iOS 中,可以使用 NSAttributedString 来设置 UITextField 的占位符颜色。以下是一个示例代码:
let placeholderText = 'Enter text here'
let placeholderColor = UIColor.gray
let attributes = [
NSAttributedString.Key.foregroundColor: placeholderColor
]
textField.attributedPlaceholder = NSAttributedString(string: placeholderText, attributes: attributes)
通过创建一个 NSAttributedString 对象,并设置其 foregroundColor 属性为所需的颜色,然后将其赋值给 UITextField 的 attributedPlaceholder 属性,就可以设置 UITextField 的占位符颜色为指定的颜色。
注意:此方法仅适用于 iOS 6 及以上版本。对于 iOS 5 及以下版本,可以通过自定义 UITextField 的子类来实现。
原文地址: http://www.cveoy.top/t/topic/cvSv 著作权归作者所有。请勿转载和采集!