【问题标题】:NSBackgroundColorAttributeName doesn't seem to work on iOS 10.3NSBackgroundColorAttributeName 似乎不适用于 iOS 10.3
【发布时间】:2023-04-09 04:50:02
【问题描述】:

我们在应用中显示一个标签,其中包含属性文本和一些突出显示颜色。为了实现这一点,我们使用以下曾经可以工作的代码:

let paddedLineAttributed = NSMutableAttributedString(string: paddedLine, attributes: [NSFontAttributeName : newFont, NSParagraphStyleAttributeName : paragraphStyle, NSBackgroundColorAttributeName : color])

但是在将我们的一台测试设备升级到 iOS 10.3 后,为标签指定的背景颜色不再生效。相反,它使用了透明的背景颜色,使标签不可见,因为我们使用与父视图颜色相同的白色文本颜色。

我怀疑 NSBackgroundColorAttributeName 是罪魁祸首,但官方 API 参考保持不变 - https://developer.apple.com/reference/appkit/nsbackgroundcolorattributename

有什么想法吗?

【问题讨论】:

  • 你可以试试这个建议-link
  • 感谢您的建议,现在会尝试一下,看看我们现在是否可以解决这个问题。

标签: swift uilabel nsattributedstring


【解决方案1】:

复制自@schystz 评论:

添加NSBaselineOffsetAttributeName: 0 可以解决问题。

let paddedLineAttributed = NSMutableAttributedString(string: paddedLine, attributes: [NSFontAttributeName : newFont, NSParagraphStyleAttributeName : paragraphStyle, NSBackgroundColorAttributeName : color, NSBaselineOffsetAttributeName: 0])

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2013-02-04
    • 1970-01-01
    • 1970-01-01
    • 2020-04-04
    • 2023-04-06
    • 2017-08-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多