UILabel截断” ...” (空格“...”)而不是“...”
所以我试图用 UILineBreakModeTailTruncation
实现 UILabel
。
因此,例如,如果文本是 “StackOverflow 是程序员的最佳网站”
,它会被截断为 “StackOverflow 是最好的...”
它需要是 < code>“StackOverflow 是最好的...”(空格+...)
有没有简单的方法来实现这个?
除了子类化和子类化之外的任何简单实现覆盖drawRect
,和/或玩弄框架,(如果它字符限制框架大小,停止它并附加“...”)?
期待有趣的实现!
So I am trying to implement UILabel
with UILineBreakModeTailTruncation
.
So, for example if the text is "StackOverflow is the best website for programmers"
, it gets truncated as "StackOverflow is the best..."
It needs to be "StackOverflow is the best ..."
(Space + ...)
Is there any easy way to implement this ??
Any easy implementations other than subclassing & overriding drawRect
, and/or playing around with the frames, (if it character limit frame size, stop it and append " ...") ??
Look forward to interesting implementations !
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
据我所知,苹果并没有为此提供任何API。您必须编写自己的实现。我会用当前字体计算 UILabel 的宽度,看看它是否超过最大宽度,如果超过,则截断文本,否则正常显示文本。
As far as I know, Apple does not provide any API for this. You have to write your own implementation. I would calculate the width of the UILabel with the current font, see if it exceeds the maximum width, if it does, truncate text, otherwise present text normally.