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:

8508 questions
120
votes
10 answers

Using `textField:shouldChangeCharactersInRange:`, how do I get the text including the current typed character?

I'm using the code below to try and have textField2's text content get updated to match textField1's whenever the user types in textField1. - (BOOL) textField: (UITextField *)theTextField shouldChangeCharactersInRange: (NSRange)range…
user265961
  • 1,353
  • 3
  • 10
  • 10
118
votes
20 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,716
  • 5
  • 32
  • 52
117
votes
14 answers

Blank space at top of UITextView in iOS 10

I have UITextView with some text in it. Everything was fine with iOS 6 but now with iOS 7 it leaves the blank space on top and then place the text below the middle of the textview. I didn't set any contentOffSet. Please Help!
Ali Sufyan
  • 2,038
  • 3
  • 17
  • 27
116
votes
17 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,475
  • 2
  • 12
  • 23
108
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
  • 52,598
  • 51
  • 134
  • 168
108
votes
14 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
  • 5,484
  • 10
  • 54
  • 95
107
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,106
  • 5
  • 26
  • 37
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
  • 46,327
  • 33
  • 91
  • 100
99
votes
5 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,211
  • 1
  • 10
  • 12
95
votes
28 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,420
  • 5
  • 31
  • 40
94
votes
18 answers

UI Test deleting text in text field

In my test I have a text field with a pre-existing text. I want to delete the content and type a new string. let textField = app.textFields textField.tap() // delete "Old value" textField.typeText("New value") When deleting string with hardware…
Tomasz Bąk
  • 6,124
  • 3
  • 34
  • 48
94
votes
37 answers

How to restrict UITextField to take only numbers in Swift?

I want the user to only enter numeric values in a UITextField. On iPhone we can show the numeric keyboard, but on iPad the user can switch to any keyboard. Is there any way to restrict user to enter only numeric values in a UITextField? Note: This…
user5034941
92
votes
8 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,976
  • 4
  • 26
  • 43
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
86
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,103
  • 5
  • 24
  • 32