Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to toggle a UILabel between editable and non-editable

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.

like image 440
KsK Avatar asked Jul 05 '12 11:07

KsK


People also ask

How do I change my UILabel?

To change the font or the size of a UILabel in a Storyboard or . XIB file, open it in the interface builder. Select the label and then open up the Attribute Inspector (CMD + Option + 5). Select the button on the font box and then you can change your text size or font.

How do you make a textfield not editable in Swift?

Set the Boolean variable to false, which enables editing in the text field. When someone taps the Done button, isEditing becomes false. Set the Boolean variable to true, which disables editing in the text field.

What is UILabel In swift?

A view that displays one or more lines of informational text.


2 Answers

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.

like image 174
Eimantas Avatar answered Oct 08 '22 22:10

Eimantas


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"

like image 40
Pochi Avatar answered Oct 08 '22 21:10

Pochi