NSLineBreakByWordWrapping on First Line but NSLineBreakByTruncatingTail For Second Line?

混江龙づ霸主 提交于 2019-12-11 00:46:29

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!