Search code examples
iosobjective-ccocoa-touchuilabelword-wrap

NSLineBreakByWordWrapping on First Line but NSLineBreakByTruncatingTail For Second Line?


Is this possible?

I want to have a two line label. On the first line, I want it to wrap on words. But for the second line, if the text is too long, I want it to truncate by tail and add the ellipses "..." after.

Any ideas on the simplest way to do this?


Solution

  • In my comment I was wrong about the line break mode. If you just drag out a UILabel, the default line break is Truncate Tail, which is what you want. If you make the label twice as high, and set the lines to 2, the text will wrap, and if too long for the second line, it will show the ellipsis. No need to do anything fancy.