Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Disabling user input for UITextfield in swift

pretty trivial question, I know. But I can not find anything online.

I need to disable the user from being able to edit the text inside of a text field. So that when the click on the text, a keyboard doesn't show up.

Any ideas?

A programmatic solution or if it is possible through storyboards would be great.

like image 575
Matt Spoon Avatar asked Apr 22 '15 08:04

Matt Spoon


People also ask

How do I restrict Uitextfield to take only numbers in Swift?

Method 1: Changing the Text Field Type from storyboard. Select the text field that you want to restrict to numeric input. Go to its attribute inspector. Select the keyboard type and choose number pad from there.

How do you dismiss a keyboard in Swift?

Via Tap Gesture This is the quickest way to implement keyboard dismissal. Just set a Tap gesture on the main View and hook that gesture with a function which calls view. endEditing . Causes the view (or one of its embedded text fields) to resign the first responder status.


1 Answers

Try this:

Swift 2.0:

textField.userInteractionEnabled = false 

Swift 3.0:

textField.isUserInteractionEnabled = false 

Or in storyboard uncheck "User Interaction Enabled"

enter image description here

like image 75
Vlad Avatar answered Sep 20 '22 04:09

Vlad