使用 secureTextEntry 为 UITextField 选择键盘语言 [英] Selecting language of the keyboard for UITextField with secureTextEntry
问题描述
我遇到了更改密码字段语言的问题.在我的应用程序中,我需要在不关心当前语言环境的情况下以希伯来语输入登录名/密码.当我尝试输入登录时,就可以了,我可以将键盘更改为希伯来语并输入登录.但是当我尝试在受保护的文本字段中输入密码时,出现的键盘没有选择语言按钮,所以我只能输入英文字母.
I'm stuck with a problem of changing language for the password field. In my application I need to enter login/password in hebrew with no care of current locale. When I try to enter login, then it is all right, I can change the keyboard to hebrew and enter login. But when I try to enter password in secured textField, the keyboard appears without select language button, so I can enter only english letters.
问题是登录名/密码可以是英语或希伯来语.
The thing is that logins/passwords could be in english or in hebrew.
如何将选择语言按钮放到受保护的文本字段中?
How can I put the select language button to the secured textField?
推荐答案
没有找到解决方案.不得不制作这个片段:
Didn't find a solution. Had to make this snippet:
-(BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string
{
textField.text = [textField.text stringByReplacingCharactersInRange:range withString:string];
NSString *pass = password;
pass = [pass stringByReplacingCharactersInRange:range withString:string];
[password release];
password = nil;
password = [[NSString stringWithString:pass] retain];
[self hideTextInTextFieldExceptOne:string];
[self performSelector:@selector(hideTextInTextField) withObject:self afterDelay:1.0];
return NO;
}
- (void)hideTextInTextFieldExceptOne:(NSString *)string
{
int lenght = [passwordTextField.text length];
for (int i = 0; i < lenght-1; i++)
{
NSRange range = NSMakeRange(i, 1);
passwordTextField.text = [passwordTextField.text stringByReplacingCharactersInRange:range withString:@"*"];
}
}
- (void)hideTextInTextField
{
NSUInteger lenght = [passwordTextField.text length];
passwordTextField.text = @"";
for (int i = 0; i < lenght; i++)
{
passwordTextField.text = [passwordTextField.text stringByAppendingString:@"*"];
}
}
这篇关于使用 secureTextEntry 为 UITextField 选择键盘语言的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!