UITextField SecureTextEntry field changes keyboard from numeric keypad to universal keyboard

I have a textField created in IB. I set the Numeric Pad keyboard type to IB. When I do secureTextEntry = YES in the method -(void)textFieldDidBeginEditing:(UITextField *)textField , my keyboard changes from the numeric keypad to the universal keyboard. I even tried to make the numeric keypad programmatic, but it still does not change. I installed it like this:

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

FYI, I can’t set textField to be safe in IB because I have a hint text, for example “4 digits”, displayed to the user in the text box until he starts typing. When he starts typing a text field, I want the entries to be safe text, so that it only displays * instead of the actual characters that it types.

Could you tell me what happened to what I am doing?

I have two more requests

  • I have a textField where I have the default text (e.g. tooltip text). I want this tooltip to be displayed to the user until it is entered. I do not want to clear this text when the user clicks on the text field, and then the default text is deleted. but I want this text to be displayed until the moment when it actually starts typing something on the keyboard, then by default it is necessary to clear and then enter the text that will be displayed in the text box. Is it possible to achieve this?

  • Is it possible to set the cursor position of a text field on the first character programmatically. This is necessary because I have the default text (tooltip text) and the cursor is at the end of the text. I want the cursor to be at the beginning of the text. How to make this possible programmatically?

+2
source share
1 answer

Have you tried using -setPlaceholder: on your UITextField? This way you won’t need to put text in a text box and then manually convert it to safe. eg.

 - (void)viewDidLoad { ... [textField setSecureTextEntry:YES]; [textField setPlaceholder:@"4-digits"]; ... } 

This will take full care of your last two questions. As for the first, though, I'm not sure if you can have a numeric keypad for a secure UITextField or not. It would seem that you cannot if it does not work programmatically.

+8
source

Source: https://habr.com/ru/post/1446459/


All Articles