uitextfield

Allow only alphanumeric characters for a UITextField

匿名 (未验证) 提交于 2019-12-03 02:08:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: How would I go about allowing inputting only alphanumeric characters in an iOS UITextField ? 回答1: Use the UITextFieldDelegate method -textField:shouldChangeCharactersInRange:replacementString: with an NSCharacterSet containing the inverse of the characters you want to allow. For example: // in -init, -initWithNibName:bundle:, or similar NSCharacterSet *blockedCharacters = [[[NSCharacterSet alphanumericCharacterSet] invertedSet] retain]; - (BOOL)textField:(UITextField *)field shouldChangeCharactersInRange:(NSRange)range replacementString:

UITextField auto-capitalization type - iPhone App

送分小仙女□ 提交于 2019-12-03 02:06:09
问题 Is there a way to set the autocapitalizationType for a UITextField so that the first letter of each word is capitalized by default? This Is An Example Of What I Want 回答1: Use textField.autocapitalizationType = UITextAutocapitalizationTypeWords; For more information please read: UITextInputTraits Protocol Reference 回答2: What we want to do is set the text field's autocapitalizationType . Objective-C: self.textfield.autocapitalizationType = UITextAutocapitalizationTypeWords Swift: self.textfield

UITextField text change event

匿名 (未验证) 提交于 2019-12-03 02:06:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 由 翻译 强力驱动 问题: How can I detect any text changes in a textField? The delegate method shouldChangeCharactersInRange works for something, but it did not fulfill my need exactly. Since until it returns YES, the textField texts are not available to other observer methods. e.g. in my code calculateAndUpdateTextFields did not get the updated text, the user has typed. Is their any way to get something like textChanged Java event handler. - ( BOOL ) textField :( UITextField *) textField shouldChangeCharactersInRange :( NSRange ) range replacementString :

Why can I not use my constant in the switch - case statement in Objective-C ? [error = Expression is not an integer constant expression]

匿名 (未验证) 提交于 2019-12-03 02:03:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: So I have an issue with using a constant variable in the following switch statement in Objective-C. I have Constants.h with the following: // Constants.h extern NSInteger const TXT_NAME; And Constants.m as: // Constants.m #import "Constants.h" NSInteger const TXT_NAME = 1; Then in TabBasic.m I am trying to use this constant in a switch-case statement: // TabBasic.m #import "TabBasic.h" #import "Constants.h" ... code ... - (IBAction)saveValue:(id)sender { if ([sender isKindOfClass: [UITextField class]]) { UITextField *txtField = (UITextField

Multi-line user input in iOS: UITextField vs UITextView

只愿长相守 提交于 2019-12-03 01:39:44
问题 I need to show users a multi-line text input "box" with a height greater than the standard height of a UITextField . What the best or most correct approach should be?: Using a UITextField and change its height in code or by applying a certain height constraint. Using an editable UITextView . This is multi-line but it has no placeholder by default, I guess I should implement that feature in code. 回答1: UITextField is specifically one line only. Use UITextView instead for multiline text. To

UITextField clearButtonMode color

匿名 (未验证) 提交于 2019-12-03 01:31:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: can I change the color of the clearButtonMode on a textField? theTextField.clearButtonMode = UITextFieldViewModeWhileEditing shows an x that is grey dark color to delete the textField, but can i show this button with white color? thanks 回答1: You'll need to create your own clear button image in this case. I would suggest taking a screenshot of the clear button and editing in photoshop. You can take that image and create a UIButton with the image dimensions. From there you can set it as the UITextField's rightView. Like so: UIButton *button =

How do I check when a UITextField changes?

匿名 (未验证) 提交于 2019-12-03 01:29:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 由 翻译 强力驱动 问题: I am trying to check when a text field changes, equivalent too the function used for textView - textViewDidChange so far I have done this: func textFieldDidBeginEditing ( textField : UITextField ) { if self . status . text == "" && self . username . text == "" { self . topRightButton . enabled = false } else { self . topRightButton . enabled = true } } Which kind of works, but the topRightButton is enabled as soon as the text field is pressed on, I want it to be enabled only when text is actually typed in? 回答1: SWIFT textField .

How to open the keyboard automatically on UITextField?

我的未来我决定 提交于 2019-12-03 01:28:25
问题 I have a very simple table and when tocuh a cell it opens a new view with one UITextfield. All I want is that the keyboard will automatically opens, without the user have to touch the UITextfield. Its all done in Interface Builder, so I am not sure how I do this. I guess I need to set the focus at some point ? Thanks 回答1: To cause the keyboard to show up immediately you'll need to set the text field as the first responder using the following line: [textField becomeFirstResponder]; You may

How to add TextField to UIAlertController in Swift

匿名 (未验证) 提交于 2019-12-03 01:23:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I am trying to show a UIAlertController with a UITextView. When I add the line: //Add text field alertController.addTextFieldWithConfigurationHandler { (textField) -> Void in } I get a Runtime error: fatal error: unexpectedly found nil while unwrapping an Optional value let alertController: UIAlertController = UIAlertController(title: "Find image", message: "Search for image", preferredStyle: .Alert) //cancel button let cancelAction: UIAlertAction = UIAlertAction(title: "Cancel", style: .Cancel) { action -> Void in //cancel code }

Right aligned UITextField spacebar does not advance cursor in iOS 7

匿名 (未验证) 提交于 2019-12-03 01:11:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: In my iPad app, I noticed different behavior between iOS 6 and iOS 7 with UITextFields. I create the UITextField as follows: UIButton *theButton = (UIButton*)sender; UITextField *textField = [[UITextField alloc] initWithFrame:[theButton frame]]; [textField setDelegate:self]; [textField setContentVerticalAlignment:UIControlContentVerticalAlignmentCenter]; [textField setContentHorizontalAlignment:UIControlContentHorizontalAlignmentRight]; textField.textAlignment = UITextAlignmentRight; textField.keyboardType = UIKeyboardTypeDefault; ...