user946414
user946414

Reputation: 135

UITextField SecureTextEntry field changes the keypad from numberpad to generic keypad

I have a textField created in IB. I have set the keypad type to Numeric Pad in IB. When i make secureTextEntry = YES in -(void)textFieldDidBeginEditing:(UITextField *)textField method , my keypad changes from numberpad to generic keypad. I even tried to make the keypad to be numeric programatically but still it doesnot changes. I have set it like this

-(void)textFieldDidBeginEditing:(UITextField *)textField{
    if(textField == self.activationCodeTextField){
        self.activationCodeTextField.secureTextEntry = YES;
        self.activationCodeTextField.keyboardType = UIKeyboardTypeNumberPad;
    }
}

FYI, I cannot set the textField to be secure in IB because i have an hint text like "4-digits" displayed to the user in the textfield till he starts typing in the text filed. Once he starts typing in the textfield, i want the entries to be a secure text so that it displays only * instead of actual characters he types.

Can you please let me know whats wrong in what I am doing?

I also have two more query

  1. I have a textField where i have some default text (like hint text). I want this hint text to be displayed to the user till the moment he starts typing. I dont want to clear this text when the user clicks on the textfield and then the default text clears away. but, i want this text to be displayed till the moment he actually starts to type something on the keypad, then the default must be cleared and then the actual typed in text to be displayed on the textfield. IS it possible to acheive this ?

  2. Is it possible to set the cursor position of textfield to the first character programatically. This is needed because, i have some default text (hint text) and the cursor is at end of the text. I want the cursor to be at the start of the text. How to make this possible programatically?

Upvotes: 2

Views: 7436

Answers (1)

codykrieger
codykrieger

Reputation: 1780

Have you tried using -setPlaceholder: on your UITextField? That way you wouldn't need to do put text in the text field, and then later manually convert it to be secure. e.g.

- (void)viewDidLoad {
    ...

    [textField setSecureTextEntry:YES];
    [textField setPlaceholder:@"4-digits"];

    ...
}

That will completely take care of your last two questions. Regarding the first, though, I'm not sure if you can have a numeric keyboard for a secure UITextField or not. It would seem that you can't if setting it programmatically has no effect.

Upvotes: 8

Related Questions