uitextfield

UITextField has trailing whitespace after secureTextEntry toggle

我的未来我决定 提交于 2019-11-30 07:53:12
I have a button that toggles between Show/Hide mode (i.e. toggles a UITextField between secureTextEntry NO and YES). The purpose of which is to allow the user to see the password they are entering. I followed the example (with the highest number of votes) here: UITextField secureTextEntry - works going from YES to NO, but changing back to YES has no effect However, when I set secureTextEntry to NO, any text that was written there ends up with a space at the end. This does not seem to be a problem when setting secureTextEntry to YES. For example, if I enter the text "mypassword" while

How to put a character limit on a UITextField

别说谁变了你拦得住时间么 提交于 2019-11-30 07:52:55
I would like to put a character limit on a UITextField but don't know how. I want it to have a maximum of 16 characters in it. How do I do this. - (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string { NSUInteger newLength = [textField.text length] + [string length] - range.length; return (newLength > 12) ? NO : YES; } 来源: https://stackoverflow.com/questions/5760150/how-to-put-a-character-limit-on-a-uitextfield

Cursor not showing up in UITextView

折月煮酒 提交于 2019-11-30 07:45:12
问题 Can anyone think of a reason that the blinking cursor would not show up in a UITextView ? I have a custom control that is just a subclass of UIView and it has a UITextView in it, but the cursor doesn't appear when it gets focus. The keyboard appears, and the text appears as you type, but there is no cursor, and I can't figure out why. Any thoughts?... 回答1: You may have changed the tint color in your custom UITextView. If the tint color is the same as the background color (normally white),

Card number first 12 digits should be secure entry and remaining 4 digits as normal

元气小坏坏 提交于 2019-11-30 07:42:44
Card number first 12 digits should be secure entry and remaining 4 digits as normal for example i am entering card number - 4111 1111 1111 1111. While entering this text in textfield first 12 digits should be secure entry and last 4 digits should be as normal entry i.e., 1111.(finally card number will looks like XXXXXXXXXXXX1111). Can any one explain me how to do it. One option is to implement the UITextField delegate method textField:shouldChangeCharactersInRange:replacementString: . In this method you would want to always return NO. But first you would update the text field's text such that

Adding space between textfield character when typing in text filed

喜夏-厌秋 提交于 2019-11-30 07:41:08
问题 I have a textfield with maximum character range 16, After every 4 characters, I want to add minus character or space and then writing The rest of the characters like this sample 5022-2222-2222-2222. there is my code but that's don't work, how can do this? if textField.text?.characters.count == 5 { let l = textField.text?.characters.count let attributedString = NSMutableAttributedString(string: cartNumberTextField.text!) attributedString.addAttribute(NSKernAttributeName, value: CGFloat(4.0),

How do I change returnKeyType while editing?

白昼怎懂夜的黑 提交于 2019-11-30 07:04:10
问题 How can I change the return key on the iPhone while it is editing. I know about myTextField.returnKeyType = UIReturnKeySearch; However, this only works if I call [myTextField resignFirstResponder]; then [myTextField becomeFirstResponder]; which hides the keyboard then brings it back. Otherwise, it just stays as the one I had before, in this case it was "Go". I need to keep switching them depending on the characters the user enters. In one line: How do I change the return key type of the

How to increase width of textfield according to typed text?

雨燕双飞 提交于 2019-11-30 05:56:30
问题 I need to increase a text field's width according to its content. When the user inputs text, then the textfield size should increase automatically. I have one close (X) button next to this text field. I have constrained the text field and button so that the text field is centered on screen, and the button is adjacent to it. (Text field should be editable, button should be clickable) Text field size is this: When I enter text in it, the size should automatically increase: How can I achieve

How to make UITextField behave like a UISearchBar in Swift?

霸气de小男生 提交于 2019-11-30 05:11:19
Hi guys I am working on an new App using UITableView and a UISearchBar in Swift and it's already working fine. But since the final project must have a complete customized searchbar, I had to move to UITextField as the input Outlet because of the customization possibilities. The problem is that I just can't figure out how to code so that the UITextField behaves like a UISearchBar. Have no idea of how I could filter the UITextField inputs and make the string usable with the UISearchBarDelegate methods. So anyone could help me out with this? EDIT: I followed Daniel's help and came up with this

Detect UITextField Lost Focus

心已入冬 提交于 2019-11-30 05:02:13
i searched a lot googling and heree, but nothing useful. I have two textfields and i don't able to recognize which one lost the focus. I tried all options, but nothing. Here the textFieldDidEndEditing : - (void) textFieldDidEndEditing:(UITextField *)textField { NSLog(@"%@", [textField state]); NSLog(@"%d", [textField isSelected]); NSLog(@"%d", [textField isFirstResponder]); NSLog(@"%d", [textField isHighlighted]); NSLog(@"%d", [textField isTouchInside]); if ( ![textField isFirstResponder] || ![textField isSelected] ) { //if ( [textField state] != UIControlStateSelected) { NSLog(@"not selected!

Assign a method for didEndOnExit event of UITextField

纵然是瞬间 提交于 2019-11-30 04:48:12
问题 How do I programmatically assign a method (observer?) to the didEndOnExit event of a UITextField object? This is easy enough to do in IB but I can't figure out how to do it in code. 回答1: I just figured it out... [mytextField addTarget:self action:@selector(methodToFire:) forControlEvents:UIControlEventEditingDidEndOnExit]; 回答2: In your view controller implement the following method: - (void)textFieldDidEndEditing:(UITextField *)textField{ //do stuff } Don't forget to set the delegate in