【问题标题】:Count the number of visible character in UILabel while truncated - Xcode Swift计算截断时 UILabel 中可见字符的数量 - Xcode Swift
【发布时间】:2018-02-26 08:10:07
【问题描述】:

是否可以在截断时计算可见字符的数量?

例如,我有一个包含 36 个字符的字符串: "This is a long looong looong string."

它在 UILabel 上显示如下: "This is a long looong..."

我的 UILabel 没有固定大小,因为它可以根据上面的视图进行扩展。如果我使用label.text.count,它将返回整个 36。我只想获取可见字符(如果计数中包含省略号,则为 21 或 24)。

这可能吗?

【问题讨论】:

    标签: ios swift xcode uilabel ellipsis


    【解决方案1】:

    您需要自己计算可见字符的数量。 查看这些相关问题:

    Calculate the range of visible text in UILabel

    How to get visible text as a string on a textView in iOS?

    【讨论】:

      猜你喜欢
      • 2016-06-07
      • 2015-05-09
      • 2019-12-05
      • 1970-01-01
      • 2012-12-04
      • 2011-06-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多