首页 > 解决方案 > 操作表文本始终为灰色(NSAttributedString.Key 不起作用)

问题描述

我正在使用带有一些文本显示的自定义操作表。使用 XCode 11.3 我不能使用 NSAttributedString.Key.foreground。以前更新之前可以用,现在没找到解决办法。

带有我的问题示例的屏幕截图

    let attributedMessageText = NSMutableAttributedString(
        string: description,
        attributes: [
            NSAttributedString.Key.paragraphStyle: paragraphStyle,
            NSAttributedString.Key.font: UIFont.systemFont(ofSize: 13.0),
            NSAttributedString.Key.foregroundColor: UIColor.red
        ]
    )

如果我想改变背景颜色,它也会变成灰色。也许有人已经面临这个问题?

标签: iosswiftnsattributedstringactionsheet

解决方案


使用私有 API 绝不是一个好主意,因为它们可能会在没有通知的情况下发生变化。我猜你使用这样的东西:

actionSheet.setValue(message, forKey: "attributedTitle")

这就是为什么这在 iOS13.3 上不起作用的原因。不幸的是,没有合法的方法可以使用公共 API 更改这些颜色。但你并不孤单,或者这里有很好的推荐


推荐阅读