uitextfield

Tap on UITextField's clear button hides keyboard instead of clearing text

廉价感情. 提交于 2019-12-03 11:09:10
问题 In iPhone, I have a view which has a UITextField . When I tap on the clear button of UITextField 's the keyboard dismissed instead of clearing the text in the UITextField . On an iPad it is working correctly. What can I do to fix this? 回答1: Just clear the field, resignFirstResponder (if you want to hide keyboard) and return NO / false Note: set Attributes inspector property of UITextField Clear Button -> Appears while editing so it will display the clear button while editing in the text field

Become first responder without animation

烂漫一生 提交于 2019-12-03 11:08:07
Is there a way for a UITextField to become first responder without the animation of the keyboard? That is, make it such that the keyboard just appears? Basically, I'm pushing a second UIViewController over the UIViewController that has the UITextField , and when that second view controller gets popped off the stack, I want the UITextField to immediately have first responder status so that when the second view controller gets popped, the user never notices the text field wasn't first responder. Right now I have it so that when it's popped, the keyboard animates up the screen, but I don't want

How to determine the length of the text in a UITextfield

与世无争的帅哥 提交于 2019-12-03 10:41:30
I have a UITextField from which I'd like to determine the width of the entered text. The bounds property has just the size of the Textfield but not of the text CGFloat width = [aTextField.text sizeWithFont:aTextField.font].width; Now that sizeWithFont: is deprecated in iOS 7.0 use CGFloat width = [tf.text sizeWithAttributes: @{NSFontAttributeName:tf.font}].width; https://developer.apple.com/library/ios/documentation/UIKit/Reference/NSString_UIKit_Additions/#//apple_ref/occ/instm/NSString/sizeWithAttributes : If you are looking for character count it is this int textLength = [someTextField.text

Getting the cursor position of UITextField in ios

﹥>﹥吖頭↗ 提交于 2019-12-03 10:34:06
I am trying to control the cursor position in the UITextField. Users cannot insert more than one character at a time into the middle of the text field. It moves it to the end of the textfield. So this post in SO: Control cursor position in UITextField It solves my problem. But I need to know the current cursor position. My code looks like this: - (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string { if (textField.tag == 201) { [myclass selectTextForInput:textField atRange:NSMakeRange(idx, 0)]; } } It is giving me an error

Display UIPickerView when UITextField is clicked

匿名 (未验证) 提交于 2019-12-03 10:24:21
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 由 翻译 强力驱动 问题: I have a screen with many text fields on it. For one particular text field, I need it to show a picker from which the user can pick state names, once the user has picked a state by clicking on the states name, the picker should disappear. I am not quite sure how to do this, I have made the Nib file which looks like this. And here is my header file: #import <UIKit/UIKit.h> #import "APIHelper.h" @interface AddNewAddressViewController : UIViewController < UIPickerViewDelegate , UIPickerViewDataSource , UITextFieldDelegate > {

How do I get the text from UITextField into an NSString?

半腔热情 提交于 2019-12-03 10:20:48
I've tried various methods, which all give me warnings. Such as userName = [NSString stringWithFormat:@"%@", [yournamefield stringValue]]; which just gives me a warning of 'UITextField' may not respond to '-stringValue' How do i do this? Jilouc Get the text inside the text field using the text property NSString *name = yourNameField.text; Eric Chai Use the text property of UITextField : NSString *userName = yourNameField.text; How about: userName = [NSString stringWithFormat:@"%@", yournamefield.text]; Two ways. It is a property and any property value can be accessed like this - yournamefield

Display UIMenuController in editingDidBegin of a UITextField

拥有回忆 提交于 2019-12-03 10:08:05
I simply want to display the UIMenuController right after a textfield has become active. What i'm doing right now is: - (IBAction)textFieldeditingDidBegin:(UITextField *)sender { // textfield menu item UIMenuController *menu = [UIMenuController sharedMenuController]; [menu setTargetRect:sender.frame inView:self.view]; [menu setMenuVisible:YES animated:YES]; } The method gets called but it just will not display the menu... If i do a touch+hold gesture on the textfield it comes up regularly. I hope there's a simple solution for that, Thanks I found a good solution to your question. You can

Dismissing the First Responder/Keyboard with multiple Textfields

瘦欲@ 提交于 2019-12-03 09:59:08
问题 Like seriously after going through this... Easy way to dismiss keyboard? ... I have multiple TextFields and a few TextViews . Is there not a way to a have a batch or group Dismiss First Responder for all text fields? Will I need to make method for each field? Maybe I overlooked something in that link? Maybe I can follow something like this: https://stackoverflow.com/questions/3282837/problem-with-multiple-textfields-to-make-the-keyboard-dissapear Would the latter make sense? Thanks in advance

Objective-C: Numbers only text field? [duplicate]

醉酒当歌 提交于 2019-12-03 09:55:51
Possible Duplicate: Iphone UITextField only integer I want to place a text field that only accepts numbers (0-9, doesn't even need decimals), but even using the "Number Pad" entry option I still get a keyboard with various symbols on it. Is there a better control for this, is there a better control for what I'm doing, or do I just have to validate input manually? The following code will allow you to only input numbers as well as limit the amount of characters that can be used. -(BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *

UITextField placeholder text: adjust to fit

旧巷老猫 提交于 2019-12-03 09:47:09
I have UITextField with longer text in it set as placeholder. What I want is for this placeholder text to adjust its font size when the width of field is too small. I already tried this solution described in other posts (programmatically and in IB) self.fieldTest.adjustsFontSizeToFitWidth = true self.fieldTest.minimumFontSize = 10.0 What am I missing here? wj2061 You can create a subclass of UITextField : class AutoSizeTextField: UITextField { override func layoutSubviews() { super.layoutSubviews() for subview in subviews { if let label = subview as? UILabel { label.minimumScaleFactor = 0.3