Disable UITextField Keyboard?

I put a numeric keypad in my application to enter numbers into a text view, but to enter numbers I need to click on the text view. As soon as I do this, a regular keyboard appears that I don't want.

How do I turn off the keyboard? Any help is appreciated.

+58
iphone cocoa-touch uitextfield iphone-softkeyboard
Apr 11 2018-11-11T00:
source share
8 answers

The inputView UITextField property is nil by default, which means that the standard keyboard is displayed.

If you assign it a custom input view or just a dummy view, the keyboard will not appear, but a blinking cursor will still appear:

UIView* dummyView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 1, 1)]; myTextField.inputView = dummyView; // Hide keyboard, but show blinking cursor 

If you want to hide both the keyboard and the blinking cursor, use this approach:

 -(BOOL)textFieldShouldBeginEditing:(UITextField *)textField { return NO; // Hide both keyboard and blinking cursor. } 
+99
Dec 02 2018-11-12T00:
source share

For Swift 2.x, 3.x, 4.x, 5.x

 textField.inputView = UIView() 

doing the trick

+57
Dec 17 '15 at 21:57
source share

If it is a UITextField, you can set its enabled property to NO.

If it's a UITextView, you can implement -textViewShouldBeginEditing: in your deletion to return NO so that it never starts editing. Or you can subclass it and override -canBecomeFirstResponder to return NO. Or you can use its editing behavior and put your number buttons in the view that you use as the text view of inputView . It is assumed that the buttons will be displayed when editing a text view. This may or may not be what you want.

+4
Apr 11 2018-11-11T00:
source share

Depending on how you work with existing buttons, this may break them, but you can prevent the keyboard from displaying the value of the textView edit property NO

 myTextView.editable = NO 
+4
Apr 11 '11 at 1:19
source share

I have the same problem when there were 2 text fields on the same view. My goal was to show the default keyboard for one text field and hide for a second and show a drop-down list instead.

 - (BOOL)textFieldShouldBeginEditing:(UITextField *)textField 

the method just didn't work as I expected for 2 text fields, the only workaround I found was

  UIView* dummyView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 1, 1)]; myTextField.inputView = dummyView; myTextField.inputAccessoryView = dummyView; myTextField.tintColor = myTextField.backgroundColor; //to hide a blinking cursor 

This will completely hide the keyboard for the target textField (DropDownList in my case) and show the default value when the user switches to the second text box (account number in my screenshot)

enter image description here

+1
Jul 25 '16 at 17:53
source share

To disable the UITextField keyboard:

  • Go to Main.Storyboard
  • Click UITextField to select it
  • Show Inspector Attributes
  • Uncheck User Interaction



To disable the UITextView keyboard:

  • Go to Main.Storyboard
  • Click UITextView to select it
  • Show Inspector Attributes
  • Uncheck Editable Behavior
0
Jul 14 '16 at 20:35
source share
 private void TxtExpiry_EditingDidBegin(object sender, EventArgs e) { ((UITextField)sender).ResignFirstResponder(); } 

In C #, this worked for me, I do not use a storyboard.

-one
Oct 28 '16 at 13:07 on
source share

In Xcode 8.2, you can do this easily by unchecking the on status checkbox.

  • Click on the text box that you want to change.
  • Go to the attirube inspector on the right.
  • Uncheck Enabled for

enter image description here

Or, if you want to do this with code. You can simply create the @IBOutlet of this text field, give it a name, and then use that variable name in the viewDidLoad function (or any custom one if you want), like this (in swift 3.0.1):

 override func viewDidLoad() { super.viewDidLoad() // Do any additional setup after loading the view. myTextField.isEditable = false } 
-2
Dec 22 '16 at 23:17
source share



All Articles