在将现有应用程序转换为暗模式时,我偶然发现了带有NSAttributedString的UITextView的初始化,以便为某些应用程序商店提供精美的印刷品。 在亮模式下看起来不错,但在暗模式下我得到黑色的黑色文本。 我提供默认前景色的第一个想法是添加以下内容:
import UIKit
let fgColor: UIColor
if #available(iOS 13.0, *) {
fgColor = .label
} else {
fgColor = .black
}
let s = try NSAttributedString(data: NSLocalizedString("""
Your payment will be charged to your iTunes Account at confirmation of purchase. Your subscription automatically renews unless auto-renew is turned off at least 24-hours before the end of the current period. Your Account will be charged for renewal within 24-hours prior to the end of the current period at the same price as the original subscription.
Terms of Service | Privacy Policy
""", comment: "legalese").data(using: String.Encoding.utf8, allowLossyConversion: false)!,
options: [.documentType: NSAttributedString.DocumentType.html.rawValue,
.defaultAttributes: [NSAttributedString.Key.foregroundColor: fgColor]],
documentAttributes: nil)
但是无论我如何尝试,都无法更改默认的前景色。 有任何想法吗?