UITextField for copy but not editable Swift

I have a UITextField in my Swift iOS app. How to make it copied but not editable?

Here is what I tried:

  • The "Enable user" setting is enabled. The field can be copied, but if you touch it, the keyboard appears.
  • Disable the "Enable user" setting. No keyboard, but not copied.

What should I do?

+6
source share
1 answer

Use a UITextView instead of a UITextField . UITextField does not have an isEditable property. The following Swift 5 code shows a possible implementation of a UITextView instance that meets 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.

+10
source

Source: https://habr.com/ru/post/974921/


All Articles