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.

uitextfield
Filter by
Sorted by
Tagged with
1792 votes
99 answers
652k views

How can I make a UITextField move up when the keyboard is present - on starting to edit?

With the iOS SDK: I have a UIView with UITextFields that bring up a keyboard. I need it to be able to: Allow scrolling of the contents of the UIScrollView to see the other text fields once the ...
598 votes
32 answers
385k views

iPhone UITextField - Change placeholder text color

I'd like to change the color of the placeholder text I set in my UITextField controls, to make it black. I'd prefer to do this without using normal text as the placeholder and having to override all ...
adam's user avatar
  • 22.5k
493 votes
38 answers
281k views

iOS - Dismiss keyboard when touching outside of UITextField

I'm wondering how to make the keyboard disappear when the user touches outside of a UITextField.
jonepatr's user avatar
  • 7,789
492 votes
46 answers
305k views

Set the maximum character length of a UITextField

How can I set the maximum amount of characters in a UITextField on the iPhone SDK when I load up a UIView?
Domness's user avatar
  • 7,605
444 votes
31 answers
229k views

Text inset for UITextField?

I would like to inset the text of a UITextField. Is this possible?
RunLoop's user avatar
  • 20.5k
419 votes
32 answers
238k views

Set padding for UITextField with UITextBorderStyleNone

I wanted to use a custom background for my UITextFields. This works fine except for the fact that I have to use UITextBorderStyleNone to make it look pretty. This forces the text to stick to the left ...
Sebastian Wramba's user avatar
369 votes
21 answers
361k views

How do I check when a UITextField changes?

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) { ...
user avatar
293 votes
11 answers
354k views

How to create a multiline UITextfield?

I am developing an application where user has to write some information. For this purpose I need a UITextField which is multi-line (in general UITextField is a single line). As I'm Googling I find a ...
raaz's user avatar
  • 12.5k
266 votes
20 answers
279k views

How to hide keyboard in swift on pressing return key?

I am using UITextfied while clicking on textfied keyboard appear but when i pressed the return key, keyboard is not disappearing. I used the following code: func textFieldShouldReturn(textField: ...
Ashwinkumar Mangrulkar's user avatar
250 votes
16 answers
145k views

Change UITextField and UITextView Cursor / Caret Color

I'm wondering about changing the color of the cursor / caret in a UITextField (And UITextView if its the same answer) in iOS. I've seen answers for OSX development, but nothing for iOS. Is this even ...
RileyE's user avatar
  • 11k
233 votes
38 answers
269k views

Move textfield when keyboard appears swift

I'm using Swift for programing with iOS and I'm using this code to move the UITextField, but it does not work. I call the function keyboardWillShow correctly, but the textfield doesn't move. I'm using ...
Pedro Manfredi's user avatar
217 votes
13 answers
48k views

iPad keyboard will not dismiss if modal ViewController presentation style is UIModalPresentationFormSheet

Note: See accepted answer (not top voted one) for solution as of iOS 4.3. This question is about a behavior discovered in the iPad keyboard, where it refuses to be dismissed if shown in a modal ...
Kalle's user avatar
  • 13.2k
202 votes
23 answers
197k views

Create space at the beginning of a UITextField

I want to leave a bit of space at the beginning of a UITextField, just like here: Add lefthand margin to UITextField But I don't know how to do that with Swift.
LinusGeffarth's user avatar
198 votes
11 answers
138k views

Adding the "Clear" Button to an iPhone UITextField

How do you add that little "X" button on the right side of a UITextField that clears the text? I can't find an attribute for adding this sub-control in Interface Builder in the iPhone OS 2.2 SDK. ...
192 votes
22 answers
200k views

How do you dismiss the keyboard when editing a UITextField

I know that I need to tell my UITextField to resign first responder when I want to dismis the keyboard, but I'm not sure how to know when the user has pressed the "Done" key on the keyboard. Is there ...
kubi's user avatar
  • 48.8k
183 votes
12 answers
176k views

Programmatically change UITextField Keyboard type

Is it possible to programmatically change the keyboard type of a uitextfield so that something like this would be possible: if(user is prompted for numeric input only) [textField setKeyboardType: ...
eric.mitchell's user avatar
180 votes
8 answers
42k views

Super slow lag/delay on initial keyboard animation of UITextField

It takes roughly 3-4 seconds for the keyboard to pop up after I touch my UITextField. This only occurs on the first time the keyboard pops up since the app launched, afterwards the animation starts ...
Vadoff's user avatar
  • 9,299
180 votes
12 answers
164k views

Having a UITextField in a UITableViewCell

I'm trying to do that for a couple of days now, and after reading tons of messages of people trying to do that too, I'm still unable to have a fully working UITextField in some of my UITableViewCells, ...
Mathieu's user avatar
  • 1,984
164 votes
15 answers
76k views

Hide the cursor of a UITextField

I am using a UITextField with a UIPickerView for its inputView, so that when the user taps the text field, a picker is summoned for them to select an option from. Nearly everything works, but I have ...
emenegro's user avatar
  • 6,941
164 votes
5 answers
144k views

Getting and Setting Cursor Position of UITextField and UITextView in Swift

I've been experimenting with UITextField and how to work with it's cursor position. I've found a number of relation Objective-C answers, as in Getting the cursor position of UITextField in ios ...
Suragch's user avatar
  • 498k
146 votes
28 answers
84k views

Detect backspace in empty UITextField

Is there any way to detect when the Backspace/Delete key is pressed in the iPhone keyboard on a UITextField that is empty? I want to know when Backspace is pressed only if the UITextField is empty. ...
marcc's user avatar
  • 12.4k
145 votes
20 answers
161k views

Max length UITextField

When I've tried How to you set the maximum number of characters that can be entered into a UITextField using swift?, I saw that if I use all 10 characters, I can't erase the character too. The only ...
giorgionocera's user avatar
145 votes
5 answers
71k views

How do I vertically center UITextField Text?

I am simply instantiating a UITextField and noticing that the text doesn't center vertically. Instead, it is flush with the top of my button, which I find kind of odd since I would expect the default ...
Joey's user avatar
  • 7,537
141 votes
9 answers
160k views

UITextField border color

I have really great wish to set my own color to UITextField border. But so far I could find out how to change the border line style only. I've used background property to set background color in such ...
dasha's user avatar
  • 1,439
133 votes
19 answers
151k views

How to set UITextField height?

I am using a UITextField. I want to increase its height but I have not found any property to do this. How can I achieve this?
Arun's user avatar
  • 3,478
127 votes
21 answers
166k views

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 = ...
informatiker's user avatar
  • 2,809
126 votes
23 answers
192k views

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 five characters. Preferably alphanumeric, -, ., and _. I've seen this ...
ishkur88's user avatar
  • 1,285
122 votes
18 answers
89k views

iPhone Keyboard Covers UITextField

I have an app where, in Interface Builder, I set up a UIView that has a text field near the bottom of the view. When I run the app and try to enter text into that field, the keyboard slides up ...
Cruinh's user avatar
  • 3,711
122 votes
7 answers
83k views

UITextField auto-capitalization type - iPhone App

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
CodeGuy's user avatar
  • 28.7k
121 votes
20 answers
195k views

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 ...
noobsmcgoobs's user avatar
  • 2,746
121 votes
10 answers
97k views

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 ...
user265961's user avatar
  • 1,363
117 votes
14 answers
43k views

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 ...
Ali Sufyan's user avatar
  • 2,038
116 votes
17 answers
97k views

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. ...
Luiz de Prá's user avatar
  • 1,475
109 votes
7 answers
75k views

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's user avatar
108 votes
3 answers
67k views

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 ...
Debajit's user avatar
  • 46.8k
108 votes
14 answers
114k views

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 } ...
Quintin Balsdon's user avatar
107 votes
14 answers
118k views

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's user avatar
  • 3,106
100 votes
5 answers
97k views

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 ...
razibdeb's user avatar
  • 1,221
97 votes
21 answers
54k views

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("...
Tomasz Bąk's user avatar
  • 6,184
95 votes
28 answers
111k views

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 ...
subzero's user avatar
  • 3,430
95 votes
37 answers
147k views

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 ...
user avatar
93 votes
8 answers
62k views

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's user avatar
  • 4,006
90 votes
5 answers
68k views

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 ...
user avatar
86 votes
16 answers
111k views

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'...
Demasterpl's user avatar
  • 2,123
85 votes
9 answers
75k views

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 ...
George McKibbin's user avatar
84 votes
29 answers
119k views

How to toggle a UITextField secure text entry (hide password) in Swift?

I currently have a UITextfield with an eye icon in it that when pressed is supposed to toggle the secure text entry on and off. I know you can check mark the "secure text entry" box in the ...
SwiftyJD's user avatar
  • 5,321
83 votes
12 answers
61k views

Programmatically Select all text in UITextField

How can I programmatically select all text in UITextField?
Mirko's user avatar
  • 2,400
82 votes
22 answers
106k views

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's user avatar
  • 12.1k
80 votes
8 answers
54k views

Indent the text in a UITextField

My question is as simple as the title, but here's a little more: I have a UITextField, on which I've set the background image. The problem is that the text hugs so closely to it's edge, which is also ...
Dyldo42's user avatar
  • 2,358
80 votes
30 answers
77k views

Formatting a UITextField for credit card input like (xxxx xxxx xxxx xxxx)

I want to format a UITextField for entering a credit card number into such that it only allows digits to be entered and automatically inserts spaces so that the number is formatted like so: XXXX XXXX ...
Can Aksoy's user avatar
  • 1,322

1
2 3 4 5
171