如何使用NSMutableAttributedString显示重音字符? [英] How to display accented characters using NSMutableAttributedString?

查看:138
本文介绍了如何使用NSMutableAttributedString显示重音字符?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的 NSString 中,我有一些重音字符和html标签,例如< i>< / i> 。我想在 NSTextField 中显示它们的文本属性。

In my NSString, I've some accented characters and html tags, such as <i></i>. I want to display them in NSTextField with text attributes to them.

当我构建attrStr时,

When I build the attrStr, I use:

NSMutableAttributedString *attrStr = [[NSMutableAttributedString alloc] initWithHTML:[text dataUsingEncoding:NSUTF8StringEncoding]
                                                                   options:@{NSWebPreferencesDocumentOption : webPreferences}
                                                        documentAttributes:NULL];

我显示的文本如下:

someTextField.attributedStringValue = attrStr;

但这需要我知道 NSString ,但问题是我不知道编码。那么如何在不知道编码的情况下构建属性字符串?

But this require I know the encoding of the NSString, but the problem is that I do not know the encoding. So how do I build an attribute string without knowing the encoding?

推荐答案

最终,我发现如果使用 NSUnicodeStringEncoding 上面,重音字符将会正确显示。

Eventually, I found that if I use NSUnicodeStringEncoding on the above, the accented chars will be displayed correctly.

这篇关于如何使用NSMutableAttributedString显示重音字符?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆