How to change placeholder color in UITextField on tvOS, so that the change is kept and it does not revert back to its default placeholder state?

一个人想着一个人 提交于 2019-12-10 19:21:05

问题


How to change placeholder color in UITextField on tvOS, so that the change is kept and it does not revert back to its default placeholder state?

In viewDidLoad() I have added the following:

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)!])

So at first the placeholder color is white, however when it looses focus it reverts back to its default state.

How to keep the change of the placeholder color?


回答1:


Basically, need to update again the properties in didUpdateFocus in the main thread

 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])
    }
}


来源:https://stackoverflow.com/questions/37788135/how-to-change-placeholder-color-in-uitextfield-on-tvos-so-that-the-change-is-ke

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!