开发者

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? 开发者_开发技巧


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜