【问题标题】:WKInterfaceLabel Attributed String Fails on WidthWKInterfaceLabel 属性字符串在宽度上失败
【发布时间】:2017-06-30 05:13:52
【问题描述】:

我正在使用属性字符串来删除WKInterfaceLabel 中的文本。这一直有效,直到文本长于手表的宽度,因此您会看到... 实际上同样的事情发生在 iOS 上;但是,您可以剪辑解决问题的内容。在手表上,剪辑不可用。

当总宽度超出屏幕边界时,如何删除可见文本?下面是代码:

let attributedString = NSMutableAttributedString(string: self.fileTextArray[i])
attributedString.addAttribute(NSStrikethroughStyleAttributeName, value: NSNumber(value: NSUnderlineStyle.styleThick.rawValue), range: NSMakeRange(0, attributedString.length))
attributedString.addAttribute(NSStrikethroughColorAttributeName, value: UIColor.red, range: NSMakeRange(0, attributedString.length))

row.translatedTextLabel.setAttributedText(attributedString)

【问题讨论】:

    标签: swift watchkit nsattributedstring wkinterfacetable


    【解决方案1】:

    这似乎是一个错误,但有一个解决方法。解决方法是使用以下代码行:

    attributedString.addAttribute(NSBaselineOffsetAttributeName, value: 0, range: NSMakeRange(0, attributedString.length))
    

    这在 Watch OS 和 iOS 中都可以解决。

    更多细节在这里:iOS 10.3: NSStrikethroughStyleAttributeName is not rendered if applied to a sub range of NSMutableAttributedString

    【讨论】:

      猜你喜欢
      • 2020-06-27
      • 1970-01-01
      • 1970-01-01
      • 2011-06-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多