Calculating number of lines of dynamic UILabel (iOS7)


There are many solutions to this questions arround but couldn’t find non-deprecated one.

I have an UILabel with mode WordWrap and fixed width of, let’s say 250. Lines are set to 0.

Here is what I tried:

UILabel *contentLabel = (UILabel*)[contentView viewWithTag:10];
CGSize size = [contentLabel.text sizeWithFont:contentLabel.font forWidth:contentLabel.frame.size.width lineBreakMode:NSLineBreakByWordWrapping];
NSLog(@"Label's height is: %d", size.height);

The output of height param is always 20 (so it’s like one line), while te text is like 30 lines long.

I need that for UIScrollView purposes.

Source: Ios7 Questions

Categorised as ios, ios7, uilabel Tagged , ,


Leave a Reply

Your email address will not be published. Required fields are marked *

Still Have Questions?

Our dedicated development team is here for you!

We can help you find answers to your question for as low as 5$.

Contact Us