2016-06-13 4 views
1

tvOSのUITextFieldでプレースホルダの色を変更すると、変更が保存され、デフォルトのプレースホルダ状態に戻りませんか?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

didUpdateFocusのプロパティを更新する必要があります:[UIControlState](https://でdeveloper.apple.com/library/tvos/documentation/UIKit/Reference/UIControl_Class/index.html#//apple_ref/c/tdef/UIControlState)。 –

+0

こんにちはダニエル。ありがとう、しかし、私は状態のUITextFieldを設定する可能性はありません。たぶんあなたの最初の考えは、UIButtonのように動作するかもしれないということでした。 –

+0

@tommagellancook私は私の場合に働いた解決策を見つけました。フォーカスのデリゲートメソッドでメインスレッドのプレースホルダフォントの色を更新しました。それがあなたと一緒に働く場合は、最後にお試しください。 –

答えて

2

基本的には、再度、あなたはおそらく、その `.Normal`状態のために起因する文字列を設定する必要があり、メインスレッド

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

メインキューコールが問題を解決してくれてありがとう – jakedunc

関連する問題