I need to disable the keyboard "Go" button when the following occur at the same time:
Username textfield is empty AND
Password textfield has focus (even if there is text already entered in the password field)
I have two text fields "txtUsername" and "txtPassword" with the following properties set:
[txtUsername setReturnKeyType:UIReturnKeyNext];
[txtPassword setReturnKeyType:UIReturnKeyGo];
[txtPassword setEnablesReturnKeyAutomatically:YES];
The "Go" button gets disabled only when the password text field is empty (doesn't matter if there is text in the username text field or not)... I'm not sure how to go about solving it when the above two conditions are met..
Instead of trying to disable the "Go" button (which is user unfriendly), why not have a "next" button instead (which would imply the user goes to the next text field to enter in required text there)?
For this, you'd do:
[txtUsername setReturnKeyType:UIReturnKeyNext];
until all the fields you want have all the text you need to do (e.g. in the password field like you were mentioning):
[txtPassword setReturnKeyType:UIReturnKeyGo];
[txtPassword setEnablesReturnKeyAutomatically:YES];
Related
I am attempting to create a calculator that calculates results as UITextField values are changed. There is no submit button I figured textFieldDidEndEditing. Everything works with the exception of the UITextField where the user enters a value. The other fields on the form are UIPickerViews. It limits entry to 1 character in the free form UITextField.
self.mortgageAmount.delegate = self
func textFieldDidEndEditing(_ textField: UITextField) {
let selectedMortgageAmount = Double((mortgageAmount.text)!)
}
If you don't have a submit button and want dynamic calculation while typing into the field, you need to use textField(_:shouldChangeCharactersIn:replacementString:), not textFieldDidEndEditing(_:).
The former triggers each time any contents in the text field are about to change. The latter triggers only when the text field is done editing, either via a submit button or some other action, like scrolling the parent scroll view that is configured to end editing on scroll.
See https://developer.apple.com/documentation/uikit/uitextfielddelegate/1619599-textfield
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
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 ?
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?
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.
I am creating a sign up page for my iphone app and am having some problems making the way the input views work for the different kinds of fields consistent. The fields are listed as cells in a table view and the editing is supposed to take place directly in the table by having appropriate input views sliding up from the bottom.
Let me focus on only two of the fields here, namely the username field and the birthday field: for the username field it makes sense to have an ASCII capable keyboard sliding up when the user presses the field whereas a date picker seems more useful in the birthday field case.
For both the keyboard and the date picker the cancel button could be located in a tool bar just above the input view. But what about the set button? If I put that in the toolbar as well I need the return key in the keyboard to go away! But that is not possible is it?
If the return key cannot be removed then I might have to live with the set button in the toolbar only in the birthday case and then use the return key as the set button in the username case - but can I then at least change the text on the return key to "Set"?
No it's not possible* to hide the "Return" key.
It is not possible to set the string to "Set" either, but could use the .returnKeyType property to change it to a limited set of strings.
theTextField.returnKeyType = UIReturnKeyDone;
(* Well you could put an opaque UIView directly above it but it's a very bad practice and generally breaks if the user chooses a different input method)
I have 2 text fields in my app and both are connected with my "devTyping" IBAction.
This method (I guess it is a method) will be called when the event "editing changed" happens.
How can I tell my method, in which text field the user is typing?
- (IBAction)devTyping {
NSLog(#"How to know in which text field the user is typing?");
}
Take a look at this question, which should be an equivalent as to what you are asking :)
You could declare the method like this:
- (IBAction)devTyping:(UITextField*)sender {
NSLog(#"The user is typing in text field %d",sender.tag);
}
And assign each textfield a tag in Interface Builder, which is just a number to identify the text field (or any other element).
What code would I use if I wanted to use a button to add a point (.) into a any selected textbox which already has a value in it. I can easily do this;
textField.text = #".";
But this only works with one text box and clears the value.
textField doesn't mean any text field it is only connected to one.
If you have many variables referencing the text fields you have. just loop (using a for loop) through them and check for the one whose editing property is set to YES.
If you want to add a fullstop to the end of the text field's text use:
textField.text = [NSString stringByAppendingString:#"."];