views:

239

answers:

1

I'm trying to join an array of objects into a string that will ultimately be used to populate the detail label of a table cell. if the text is too long it will automatcally truncate and add an elipse at the end.

I want to avoid this by checking that the string is less than say 40 characters and adding an elipse in the middle instead.

so if my array is "one", "two", "three", "four" and "five" assuming they added up to more than 40 characters and my separator is ">", it may look like "one > two > three > four..." if it were automatically truncated.

Instead I want it to look like "one > two >... > five" so I always at least the first and last item from the array.

any ideas?

+8  A: 

I would just use a UILabel and set its lineBreakMode to UILineBreakModeMiddleTruncation. Then just use -[NSArray arrayComponentsJoinedByString:] to join the elements together.

Ben Gottlieb
Apple has really thought of everything, haven't they.- thanks for the tip.
Ward