Is it possible to have a UILabel
that consists of multiple \n
-delimited lines to have lines with their width > the label width to be truncated and not wrapped?
Suppose I have some text like the following:
- This is a really long first line of text that is too long to fit horizontally
- Short line
- Another short line
I want this to appear in my UILabel
like so:
1. This is a really long first line of text... 2. Short line 3. Another short line
However what is happening is I'm getting this:
1. This is a really long first line of text that is too long to fit horizontally 2. Short line...
The third line is getting cut off. I've set the number of lines to 3
, but it is still wrapping the first long line. It doesn't seem to matter what I set the line breaks property to on the label--it always wraps that first line. Is there any way to prevent wrapping completely on the label?
I don't think this is possible with any setting you can apply to your label. One way to do it, is to break the string into its individual lines, truncate any line that needs it so that it (with an added ellipsis) fits on one line, then put the string back together with line breaks. Something like this should work for any number of lines,
If you want to truncate by character instead of by word, you can pass NSStringEnumerationByComposedCharacterSequences instead of NSStringEnumerationByWords to the options parameter of enumerateSubstringsInRange:options:usingBlock:.
Of course, you could do it the easy way; stack 3 labels on top of each other, and give each one a line of your text :)