Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UILabel sizeToFit method not working properly

Tags:

I'm trying to show a long chunk of text inside a UILabel in one line. The UILabel is a subview of UIScrollView so I can scroll and see the entire UILabel.

My problem is that the sizeToFit method only partialy works.

textLabel.attributedText = attributedString; textLabel.numberOfLines = 1; [textLabel sizeToFit]; textScrollView.contentSize = CGSizeMake(textLabel.frame.size.width, textLabel.frame.size.height); 

The UIScrollView content size gets big enough to show the entire UILable, but for a line like:

so i'll try to share some of them here every once in a while."

The UILabel shows:

so i'll try to share som...

What am I doing wrong?

like image 304
YogevSitton Avatar asked Nov 18 '13 08:11

YogevSitton


1 Answers

Turns out the code is just fine - but the Use Autolayout was checked. Unchecked it - everything works just great...

like image 152
YogevSitton Avatar answered Oct 13 '22 00:10

YogevSitton