6

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?

Sergey Kalinichenko
  • 714,442
  • 84
  • 1,110
  • 1,523
rocket101
  • 7,369
  • 11
  • 45
  • 64

1 Answers1

10

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.

Imanou Petit
  • 89,880
  • 29
  • 256
  • 218