有没有办法像这样在本地化文件中加粗一些单词?
"Pending network connection" = "<b>Pending</b> network connection";
我里面有这个字符串,我只想强调某些单词:
"camSave" = "To complete onboarding:\n1. Tap Save and disconnect to disconnect from the camera.\n2. Connect to the internet.\n3. Log in to Cloud.";
顺便说一句我想在警报中使用它
您实际上可以将HTML标记与一起使用NSAttributedString
。这是我使用的:
static func convertFromHTMLString(_ input: String?) -> NSAttributedString? {
guard let input = input else { return nil }
guard let data = input.data(using: String.Encoding.unicode, allowLossyConversion: true) else { return nil }
return try? NSAttributedString(data: data, options: [NSAttributedString.DocumentReadingOptionKey.documentType : NSAttributedString.DocumentType.html], documentAttributes: nil)
}
因此,我使用UTF8格式将输入字符串转换为原始数据。然后,我使用带有适当标志的带有数据的属性字符串的构造函数NSAttributedString.DocumentReadingOptionKey.documentType : NSAttributedString.DocumentType.html
。
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句