表示/非表示のパスワード切り替えが選択されるたびに呼び出されるメソッドを作成してください。このメソッドの中で、フォントをnilに設定してから、フォントをカスタムフォントとフォントサイズに設定します。また、viewWillAppearメソッドでカスタムフォントとサイズを設定する必要があります。このメソッドの中で、あなたはそれを再設定しています。
この方法で、あなたは(あなたのテキストフィールドが脆弱作ることができる)secureTextEntry
を無効にする必要はありません、あなたはtextFieldDidBeginEditing
やtextFieldDidEndEditing
を使用する必要はありません。
コード例:上記
//if the password is obscured and the toggle to show it has been turned on, display password. Else, obscure it.
- (IBAction)togglePasswordVisibility:(id)sender {
// Xcode contains a bug where the font changes to default font if these two lines of code are not included.
self.passwordInputTextField.font = nil;
self.passwordInputTextField.font = [UIFont fontWithName:@"myCustomFontName" size:myDesiredFontSize]; //set this in viewWillAppear as well!
if (self.passwordInputTextField.secureTextEntry == YES) {
self.passwordInputTextField.secureTextEntry = NO;
[self.showHideButton setTitle:@"HIDE" forState:UIControlStateNormal];
} else {
self.passwordInputTextField.secureTextEntry = YES;
[self.showHideButton setTitle:@"SHOW" forState:UIControlStateNormal];
}
}
私はまったく同じ(イライラする)問題を経験しています。解決策を提供できないという申し訳はありませんが、私は確信しています。 – Luke
私はちょうど別の質問でこれに答えました。ここで自分の答えを確認してください: http://stackoverflow.com/a/20969693/1578927 – Segev
私はhttp://stackoverflow.com/questions/20969451/uitextfield-securetextentry-bullets-with-a-custom-font/20969693#だと思います20969693は最高の答えです。クラスをオーバーライドします。 –