如何在tvOS上的UITextField中更改占位符颜色,以便保留更改并且不会恢复到其默认的占位符状态?
在viewDidLoad()中,我添加了以下内容:
self.txfUsername?.attributedPlaceholder = NSAttributedString(string: "Email", attributes:[NSForegroundColorAttributeName: UIColor(red:1.0, green:1.0, blue:1.0, alpha:1.0), NSFontAttributeName:UIFont(name:"GothamBook", size:38.0)!])
所以首先占位符颜色是白色,但是当它失去焦点时它会恢复到默认状态。
如何更改占位符颜色?
答案 0 :(得分:5)
基本上,需要再次更新主线程 didUpdateFocus 中的属性
override func didUpdateFocus(in context: UIFocusUpdateContext,
with coordinator: UIFocusAnimationCoordinator) {
DispatchQueue.main.async {
self.emailTextField.attributedPlaceholder = NSAttributedString(string: emailTitle,
attributes: [NSForegroundColorAttributeName:UIColor.white])
self.passwordTextField.attributedPlaceholder = NSAttributedString(string: passwordTitle,
attributes: [NSForegroundColorAttributeName:UIColor.white])
}
}