Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UITextField copyable but not editable Swift

I have a UITextField in my Swift iOS app. How do I make it copyable, but not editable?

Here's what I've tried:

  1. Setting "User Interaction Enabled" to on. The field is copyable, but if one touches it, a keyboard pops up.
  2. Setting "User Interaction Enabled" to off. No keyboard, but not copyable.

What should I do?

like image 746
rocket101 Avatar asked Sep 06 '14 17:09

rocket101


1 Answers

Use UITextView instead of UITextField. UITextField does not have an isEditable property. The following Swift 5 code shows a possible implementation of a UITextView instance that matches your requirements:

textView.isUserInteractionEnabled = true
textView.isEditable = false

According to the documentation, isUserInteractionEnabled determines whether user events are ignored and removed from the event queue and isEditable indicates whether the receiver is editable.

like image 86
Imanou Petit Avatar answered Sep 29 '22 08:09

Imanou Petit