UILabel截断” ...” (空格“...”)而不是“...”

发布于 2025-01-07 23:54:55 字数 368 浏览 5 评论 0原文

所以我试图用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

绿萝 2025-01-14 23:54:55

据我所知,苹果并没有为此提供任何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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文