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.
I like to do it like old times. You just use a custom UITextField Class like this one:
If you want to do it while keeping the user interaction on. In my case I am using (or rather misusing)
isFocused
This way it will focus but keyboard won't show up.
Swift 4.2 / Xcode 10.1:
Just uncheck behavior Enabled in your storyboard -> attributes inspector.
Try this:
Swift 2.0:
Swift 3.0:
Or in storyboard uncheck "User Interaction Enabled"
Another solution, declare your controller as UITextFieldDelegate, implement this call-back:
In storyboard you have two choise:
The diffierence between these choise is:
the appearance of UITextfild to display in the screen.
Within code:
textfield.enable = false
textfield.userInteractionEnabled = NO
Updated for Swift 3
textField.isEnabled = false
textfield.isUserInteractionEnabled = false