在 Localizable.strings 中
"rulesText" = "No illegal posting! \n No weird stuff! \n There is no tolerance for objectionable content, they will be removed!";
我可以把这一部分加粗吗?像 没有奇怪的东西! 或使用 unicode 字符的这种意义上的东西?还是其他方式?
我是这样使用的:
textView.text = "\n\n " + NSLocalizedString("rulesText", comment: "")
最佳答案
更简单的方法是使用 NSMutableAttributedString ,同时在 textView.text 中使用。这是一个例子:
NSMutableAttributedString *attrString = [[NSMutableAttributedString alloc]
initWithString: NSLocalizedString("rulesText", comment: "")];
[attrString beginEditing];
[attrString addAttribute:kCTFontAttributeName
value:[[UIFont boldSystemFontOfSize:12] fontName]
range:NSMakeRange(2, 4)]; // use range as per your character index range
[attrString endEditing];
使用这个它会自动加粗字符,从第二个索引开始,然后是 4 个字符。 例如: 1234567890 - 1234567890
希望这对您有所帮助。
对于 SWIFT 语言:
let font:UIFont? = UIFont.boldSystemFontOfSize(12.0)
myMutableString.addAttribute(NSFontAttributeName, value: font!, range: NSRange(location: 2, length: 4));
关于ios - 有没有一种 unicode 方法可以使字符串的一部分变为粗体?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27397380/