Ward
Ward

Reputation: 3318

Cocoa array to string truncated

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?

Upvotes: 1

Views: 564

Answers (1)

Ben Gottlieb
Ben Gottlieb

Reputation: 85532

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

Upvotes: 8

Related Questions