17

How to make UILabel text editable on UILongPressGestureRecognizer. So that on long press it converts to editable and after removing focus from uilabel it become readonly.

Pfitz
  • 7,336
  • 4
  • 38
  • 51
KsK
  • 675
  • 1
  • 10
  • 22

2 Answers2

15

You can't do that. You'd have to exchange controls between UILabel and UITextField or make a subclass of UIControl to do that for you.

Eimantas
  • 48,927
  • 17
  • 132
  • 168
7

uilabels are not editable by the user, use textfield instead. You can adjust the properties of the textfield to make it look like a label.

Then simply set the interaction to disabled to simulate a label and add "something" on the area like an invisible view or button or something to detect the longpressgesture in this part. then when it does programatically set the focus to it. when the user pushes return the focus will be lost and it wont it will go back to being a "label"

Pochi
  • 13,391
  • 3
  • 64
  • 104