iOS-在Localizable.strings中以粗体字强调 [英] iOS - Emphasise with bold strings in Localizable.strings
问题描述
在可本地化文件中是否有这样的粗体字显示方法?
Is there a way bold some words inside the Localizable file like so?
"Pending network connection" = "<b>Pending</b> network connection";
我里面有这个字符串,我只想强调单词:
I have this string inside and i want to emphasis only certen words:
"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
一起使用.这就是我用的:
You can actually use HTML tags with NSAttributedString
. This is what I used:
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
的带有数据的属性字符串的构造函数.
So I convert an input string to raw data using UTF8 format. Then I use a constructor of attributed string with data using appropriate flags NSAttributedString.DocumentReadingOptionKey.documentType : NSAttributedString.DocumentType.html
.
这篇关于iOS-在Localizable.strings中以粗体字强调的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!