Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

Narendar Singh

macrumors member
Original poster
Jun 22, 2012
76
0
INDIA
I have a UILabel, I want check no of lines at run time based on the text I display in label.

Some times I have to display short text and some time very long string. In very long text I have to display "read more" button but in short string only the I have to display string. How to achieve this.

I have to display normally 3 lines but if it goes more than 3 lines then I need to display "read more button"

Thanks
 
One way to accomplish this would be to use textRectForBounds:limitedToNumberOfLines: to determine if the text fits in the area for 3 lines if it doesn't then you can display the show more button.
 
Thanks Guys,

My approach is, I am using sizeToFit() it returns the actual number of lines based on its contents, for say if content is just small text like "My name is Narendar" then it returns 1 line after using sizeToFit and if content is more it returns maximum no of lines.

Thanks :)
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.