[英]how to change the preamble text colour of a UITextField
UITextField
的.textColor
更改了初始前导文本的颜色以及用户可以输入的任何后续文本的颜色。 我要使序言颜色为红色,而随后的文本为黑色-可以吗?
您不能在Interface Builder中设置占位符文本的颜色,但是如果您在Interface Builder中设置文本的颜色,则可以使用诸如
self.textField.attributedPlaceholder = NSAttributedString(
string: self.textField.placeholder!,
attributes: [NSForegroundColorAttributeName:UIColor.green])
如果您不使用Interface Builder,则可以直接指定所需的字符串
self.textField.attributedPlaceholder = NSAttributedString(
string: "My placeholder text",
attributes: [NSForegroundColorAttributeName:UIColor.green])
使用占位符作为前导文本,并可以使用textField.attributedPlaceholder
向占位符提供textcolor
现在您可以为textField设置两种颜色。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.