UILabel auto resize and add scroll bar if necessary? - ios

I've looked around for an answer here but didn't come along one that really helped me. directing me to a proper answer I may have missed is greatly appreciated too.
I have a label defined in the simplest manner :
IBOutlet UILabel *eventIDLabel;
IBOutlet UILabel *eventTitleLabel;
IBOutlet UILabel *eventDescriptionLabel;
now the description label can vary in content. May have 1 line or multiple lines. I want the label to resize automatically. Now I also want that if more lines than current screen can show, user is enable to scroll down and see the whole content of label.
Very trivial question probably but I am really new and hoping you guys could help.
thanks :D

You could use a UITextView. UITextView automatically can be scrolled, when the entered text ist to long.

You can use [myLabel sizeToFit]
You can also read more about it here
Also if you know it's going to be relatively long, you can consider using TextView which will provide the text scrolling
Hope I helped

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.

Animate text one by one of UITextView

how to display text of textview one by one with animation, but I don't know how to do that.
For animate the textview is ok, but no luck for text.
I need help, and thank for answering !

UILabel fit to text and positioned in a correct way

If you first take a look at the following screenshot.
Like you can see, I have a custom cell with on top an UIImageView, A UILabel, An UIimageview and another UILabel
The first UIImageView should always stick to the right. That's not a problem for me.
I can't figure it out how to fix my 2 UILabels and the snake-like image. These should follow up each other with always the same margin between them. The two UILabel always contains names of people. So if my first UILabel contains a very long name, it should also looks nice.
You can compare it a little bit with what Facebook is doing.
Now my question is, how can I achieve this? I'm trying to work with autolayout.

Using UITextView

I am trying to create a textview that holds a 3 line string. As the user works, the string will update and become wider, the height (number of lines) will remain the same. Reading through the documentation I understand that the size of the container cannot change, it is readonly.
I have code that places text into the text property of a UITextView but it will not scroll the text right or left. I played around with inserting a UIView into the textview and believe that will work, but doesn’t seem like the way to about this. I’m kind of figuring that I need a custom UITextView class and a custom NSTextContainer. Wondering if the proper direction? Any help is appreciated.
Thanks,
Jeff

How can I make/program a UIlabel to scroll horizontally upon user input?

I'm making a simple calculator in iOS, and I want the user to be able to scroll the label horizontally when the end gets truncated.
How would I go about doing this? My original idea was to make two buttons that would move the label left or right by using stringpadtoLength type of method, but that seemed inefficient.
I see two ways of building this.
Use a UITextView and always return NO from -textFieldShouldBeginEditing:. This should get you 90% the way there very fast.
Build a custom control using a UIScrollView which contains a UILabel that uses -sizeToFit. This will be a bit more work, but will do exactly what you expect.
I went for Jefferey's second suggestion because I thought it would give a "cleaner" result. Turns out, it's not that easy to implement. Here's what you have to be careful about when you're putting a single-line UILabel inside of UIScrollView, in order to be able to scroll horizontally through the text.
The parent UIViewController should have the box "Adjust scroll view
insets" unchecked. If you forget this your text may be placed below the content of the UIScrollView, meaning that you can only see it if you hold it while over-scrolling down.
Call [self.toolboxItemNameLabel sizeToFit]; in your UIViewController's viewDidLoad in order to set the right size for your UILabel. This ensures that the scrolling is comfortable, going from the left to the right of the text.
When using autolayout, you must add constraints for the leading and trailing space to container of the UILabel which is inside of the UIScrollView. Thanks to this great post for the answer.

Resources