【发布时间】:2019-10-10 06:33:34
【问题描述】:
我正在使用 NSMutableAttributedString 在标签中显示多字体和彩色文本。 NSMutableAttributedString 在 iOS 13 中无法正常运行,但相同的代码在 iOS 11 和 12 版本中运行良好。
let hdAttributedText = NSMutableAttributedString(string: "Sample", attributes: [NSAttributedString.Key.font: UIFont(name: "HelveticaNeue", size: 14.0)!, NSAttributedString.Key.foregroundColor: UIColor.black])
hdAttributedText.append(NSAttributedString(string: " "))
hdAttributedText.append(NSAttributedString(string: "Description", attributes: [NSAttributedString.Key.font: UIFont(name: "HelveticaNeue-Medium", size: 14.0)!, NSAttributedString.Key.foregroundColor: UIColor(red: 0.29, green: 0.70, blue: 0.36, alpha: 1)]))
logoTextLabel.attributedText = hdAttributedText
预期结果是“示例描述”。在此文本中,“示例”应为黑色文本的常规字体,“描述”应为绿色的中等字体
【问题讨论】:
-
“没有按预期工作”是什么意思?它显示为什么?
UIFont.eX_Regular_14是什么? -
@Sweeper 我正在使用上面的代码将标签文本显示为两种不同的字体和颜色,但它不起作用。相同的代码在 iOS 11 和 12 版本中运行良好... UIFont.eX_Regular_14 是我的 UIFont 扩展
-
如何它不起作用?运行该代码的实际结果是什么?你能说明
UIFont.eX_Regular_14是如何实现的吗? -
static var eX_Regular_14: UIFont {return UIFont(name: "PFDinTextArabic-Regular", size: viewWidthPercent(percent: 3.73))!}
-
您应该在您的问题中edit 该信息,并提供minimal reproducible example。你还没有说它是怎么不工作的。
标签: swift xcode nsattributedstring ios13 nsmutableattributedstring