Questions tagged [uitextfield]

A UITextField object is a control that displays editable text and sends an action message to a target object when the user presses the return button. You typically use this class to gather small amounts of text from the user and perform some immediate action, such as a search operation, based on that text.

A UITextField object is a control that displays editable text and sends an action message to a target object when the user presses the return button. You typically use this class to gather small amounts of text from the user and perform some immediate action, such as a search operation, based on that text.

In addition to its basic text-editing behavior, the UITextField class supports the use of overlay views to display additional information (and provide additional command targets) inside the text field boundaries. You can use custom overlay views to display features such as a bookmarks button or search icon. The UITextField class also provides a built-in button for clearing the current text. A text field object supports the use of a delegate object to handle editing-related notifications.

Resources:

8328 questions
114
votes
20 answers

Swift add icon/image in UITextField

I would like to add icon/image in UITextField. The icon/image should be left to placeholder. I tried this: var imageView = UIImageView(); var image = UIImage(named: "email.png"); imageView.image = image; emailField.leftView = imageView; Thanks.
informatiker
  • 2,429
  • 4
  • 15
  • 13
112
votes
15 answers

How to disable UITextField editing but still accept touch?

I'm making a UITextField that has a UIPickerView as inputView. Its all good, except that I can edit by copy, paste, cut and select text, and I don't want it. Only the Picker should modify text field. I've learned that I can disable editing by…
Luiz de Prá
  • 1,435
  • 2
  • 12
  • 23
110
votes
21 answers

How to dismiss keyboard iOS programmatically when pressing return

I created a UITextField programmatically making the UITextField a property of the viewController. I need to dismiss the keyboard with the return and the touch on the screen. I was able to get the screen touch to dismiss, but pressing return is not…
noobsmcgoobs
  • 2,596
  • 5
  • 26
  • 48
108
votes
14 answers

How to make return key on iPhone make keyboard disappear?

I have two UITextFields (e.g. username and password) but I cannot get rid of the keyboard when pressing the return key on the keyboard. How can I do this?
K.Honda
  • 3,068
  • 5
  • 24
  • 36
107
votes
3 answers

Getting the Value of a UITextField as keystrokes are entered?

Let's say I have the following code: IBOutlet UITextField* nameTextField; IBOutlet UILabel* greetingLabel; I'd like the greetingLabel to read "Hello [nameTextField]" as soon as the user presses any key. What I need basically is the iPhone…
Debajit
  • 43,330
  • 32
  • 87
  • 97
105
votes
7 answers

UITextField - capture return button event

How can I detect when a user pressed "return" keyboard button while editing UITextField? I need to do this in order to dismiss keyboard when user pressed the "return" button. Thanks.
Ilya Suzdalnitski
  • 49,863
  • 47
  • 128
  • 166
99
votes
13 answers

How to add TextField to UIAlertController in Swift

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…
Quintin Balsdon
  • 4,546
  • 8
  • 45
  • 87
96
votes
4 answers

how to add an action on UITextField return key?

I have a button and text textfield in my view. when i click on the textfield a keyboard appears and i can write on the textfield and i also able to dismiss the keyboard by clicking on the button by adding: [self.inputText resignFirstResponder]; Now…
razibdeb
  • 1,171
  • 1
  • 9
  • 12
95
votes
27 answers

UITextfield leftView/rightView padding on iOS7

The leftView and rightView views of an UITextField on iOS7 are really close to the textfield border. How may I add some (horizontal) padding to those items? I tried modifying the frame, but did not work uint padding = 10;//padding for…
subzero
  • 3,288
  • 5
  • 28
  • 40
94
votes
21 answers

Set the maximum character length of a UITextField in Swift

I know there are other topics on this but I can't seem to find out how to implement it. I'm trying to limit a UITextField to only 5 Characters Preferably Alphanumeric and - and . and _ I've seen this code func textField(textField: UITextField,…
ishkur88
  • 965
  • 1
  • 7
  • 12
90
votes
5 answers

How do you obscure text in a password field in an iPhone Application?

I have a password field in my application (UITextField). When user enters text in the field, I want it to display * instead of the text they entered. I have tried using the UIControlEventEditingDidEnd of UITextField but it only shows one * at the…
jaynaiPhone
85
votes
9 answers

How to add a 'Done' button to numpad keyboard in iOS

So, the numpad keyboard doesn't come with a 'Done' or 'Next' button by default so I'd like to add one. In iOS 6 and below there were some tricks to add a button to the keyboard but they don't seem to be working in iOS 7. First I subscribe to the…
George McKibbin
  • 1,283
  • 1
  • 11
  • 14
84
votes
15 answers

Allow only Numbers for UITextField input

The iPad does not have a "Numpad" keyboard like the iPhone/iPod does. I'm looking to find how I can restrict the user's keyboard to only accept values 0 through 9. I would imagine using UITextField's "shouldChangeCharactersInRange" but I don't know…
Demasterpl
  • 2,037
  • 4
  • 24
  • 32
82
votes
22 answers

Check that a input to UITextField is numeric only

How do I validate the string input to a UITextField? I want to check that the string is numeric, including decimal points.
g.revolution
  • 10,884
  • 19
  • 74
  • 102
81
votes
6 answers

Disable UITextField Predictive Text

With the release of iOS 8 I would like to disable the predictive text section of the keyboard when I begin typing in a UITextField. Not sure how this is done, any help would be appreciated!
Mike Simz
  • 3,582
  • 4
  • 18
  • 34