How to change UILabel text with user typing message - ios

Is it possible to change the UILabel text by user interaction? Or is it necessary to do it with a UITextField element?
Can you tell me the way of doing it?

I don't think that it's possible to change the UILabel text by user interaction.
I would use a UITextField with no borders to make it look like a UILabel. You can do this using the Attributes Inspector in the storyboard.

UILabel is inherently not editable, from the class reference:
The UILabel class implements a read-only text view.
You would have to use a UITextField or a UITextView - UITextView being more like a UILabel than a UITextField.
From the UITextView class reference:
The UITextView class implements the behavior for a scrollable, multiline text region. The class supports the display of text using custom style information and also supports text editing. You typically use a text view to display multiple lines of text, such as when displaying the body of a large text document.

Related

Make multiline UILabel wrap a button

I am using storyboard to design my UIView. But I've stuck at the task: I have a multiline UILabel, UIView and UIButton. I want to make UILabel to wrap my button - the fist line of the text has a trailing constraint to UIButton another one to it's super view. And if my UILabel has no text I got a view at the bottom of label and I need to make this view trailing constraint to UIButton but if I got a free space - to it's superview.
Screenshot example:
I want to jump second line word after 'pyat' . Sorry for my poor english, hope that picture could help to explain my question.
Is it possible to make it directly in IB?
Perhaps instead of using UILabel you can try UITextView by using its textView.textContainer.exclusionPaths property to define a button container area to exclude.
Have a look at the sample code with a reported issue for selected and editable case.
As I remember you must limit the app deployment target minimum to 7 or later if using this property.
Hope that helps!
What you want to do is not supported out of the box and will take a lot of work because it will require subclassing UILabel and overriding drawRect.
An easy solution is to set attributed text on the label and use that to format the specific word to look like a button. UILabel attributed text supports hyperlink like behavior.

Which component use for displaying a paragraph of text in iOS?

I want to show a paragraph of text. I have tried UILabel but this makes the text vertically aligned: it does not start from top. If I use UITextView and disable the properties selectable and editable it behaves like UILabel. Which component should I use?
You can use UILabel to TextView with NSAttributtedString.
Also you can also set your ULLabel or textview text attribute from storyboard .

How to resize the UITextField in IOS

- How to increase the height of the text field in order to accommodate multiple lines, as the text field grows accordingly.
- I want something like multiple line attribute in android.
UITextField not supporting multiple lines text place UITextView in the place of UITextField.
Look at UITextView and not a UITextField.
Use HPGrowingTextView for iOS for multiple lines textview

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.
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.
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"

iOS - how do I make a text field taller than 1 line?

I am making my first text field, and I am looking for more of a text area that the person can fill out. Xcode disables for me the ability to extend it to more than one line. Is it possible? If so, how do I do that?
Thanks!
You want a UITextView, which is an editable field that can accomodate more than one line of text.
A multiline UITextField is implemented by the UITextView and making sure its editable property is set to YES.
The UITextView class implements the behavior for a scrollable, multiline text region.

Resources