Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Change the default '...' at the end of a text if the content of a UILabel doesn't fit

I have a UILabel in my iPhone project that has a fixed width and height but it's content can vary depending what the user is looking at. Sometimes the text is to big for the UILabel and that is when the string: '...', gets added to the end of the line. I wonder if I could change this string to something else, for instance: '(more)'.

Thanks!

like image 716
Mattias Farnemyhr Avatar asked May 01 '12 00:05

Mattias Farnemyhr


1 Answers

Unfortunately, it appears that such an option is not included on iOS, as per this similar question: How to change truncate characters in UILabel?

However, as the answers in the aforementioned question state, this can be easily done yourself. All you really need to do is find where the string gets truncated and subtract the amount needed for your chosen ending character(s). Then put the remainder in a separate string.

For this method, this answer would also be useful:

As Javanator said you would have to do your own truncation. You shuld use the sizeWithFont:forWidth:lineBreakMode: message on the UIKit additions to NSString class to get the width of a string with a certain font. This will handle all types of fonts.

like image 166
Zigsaz Avatar answered Oct 17 '22 01:10

Zigsaz