问题
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?
回答1:
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.
回答2:
Have you tried using the setTruncatesLastVisibleLine:YES
property on UITextField
?
I know this is only on UITextField
but if you remove any border (and disable editing) it looks just like a UILabel, and you will get the functionality you desire.
textField.enabled = NO;
textField.borderStyle = UITextBorderStyleNone;
来源:https://stackoverflow.com/questions/15536260/nslinebreakbywordwrapping-on-first-line-but-nslinebreakbytruncatingtail-for-seco