ios - 快速更改占位符文本颜色

标签 ios swift

如何通过 Swift 更改 UITextField 的占位符文本颜色?我似乎无法访问占位符属性。谢谢

最佳答案

您可以使用属性字符串 设置占位符文本。将颜色设置为属性 属性(property)。

   textField.attributedPlaceholder = NSAttributedString(string:"placeholder text",
   attributes:[NSForegroundColorAttributeName: UIColor.yellowColor()])

swift 5

textField.attributedPlaceholder = NSAttributedString(string:"placeholder text", attributes:[NSAttributedString.Key.foregroundColor: UIColor.yellow])

关于ios - 快速更改占位符文本颜色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27683383/

相关文章:

ios - 如何更改键盘的宽度

image - 如何使用 NSJSONSerialization 将接收到的数据解码为 base64EncodedString 并将其转换为 Swift 中的 NSData

ios - View Controller 不会初始化

ios - 更改 UITableView 部分标题的字体大小

ios - 如何在快速发送到 json 解析器之前删除 xml 标签

xcode - 在启动时决定 Storyboard

iphone - Objective-C:在字符串中查找数字

html - Swift - 将 HTML 文本转换为属性字符串

ios - Spritekit 子类节点显示为 nil

ios - Alamofire 网络获取的完成处理程序