Reputation: 839
I would like my users to be able to edit a UIlabel
in my app, similar to how the UITextView
, when clicked, brings up a keyboard to edit the text. I want to use a UILabel
instead of a UITextView
because I need to be able to hide this view and it does not seem possible to hide a UITextView
. I have also tried using a UITextField
but this does not work either because I need the content to wrap.
Upvotes: 0
Views: 306
Reputation: 124997
Is it possible to make a UILabel editable in swift?
Not directly; you'd have to replace it with an object that supports editing. The UILabel
docs say, right at the top:
A view that displays one or more lines of informational text.
In other words, UILabel
is for display of text; there's nothing in there that supports editing. So, if you want to let the user edit the content of a label, you have to temporarily replace the label with an editable object such as UITextView
or UITextField
or something of your own creation.
TL/DR: If you're using a label for text that needs to be editable, you're probably using the wrong tool for the job.
I want to use a UILabel instead of a UITextView because I need to be able to hide this view and it does not seem possible to hide a UITextView.
I'm not sure why you'd say that; UITextView
is a subclass of UIView
, and therefore it has a hidden
property just like every other view. There's also an alpha
property that doesn't so much hide the view as make it transparent, but which may still be useful in some cases. And one more option, if the previous two don't work for some reason, is to "hide" the view by removing it from the view graph. But just setting the hidden
property should be all you need.
Upvotes: 1