在 UILabel 中显示重音符号和其他 UTF-8 字符
我有一个小应用程序,它列出了来自世界各地的某些人的名字,其中一些名字使用的字符不是正常的 ASCII
字符,例如 DÌaz 或 ThÈrËse。
这些字符串在 Xcode 中显示得很好,但是当我将它们放入 UILabel
中时,它们的行为却出乎意料。
我的问题是:有没有办法设置 UILabel
来获取 Xcode 中的确切字符串,并正确显示它,即使它是 UTF -8
字符(或任何其他与此相关的字符编码)?
I have a little app which lists the names of certain people from around the world, and some of those names use characters that are not normal ASCII
characters, like DÌaz, or ThÈrËse for example.
The strings show up in Xcode just fine, but when I put them in a UILabel
, they behave unexpectedly.
My question is: Is there a way to set up a UILabel
to to take the exact string in Xcode, and display it properly, even if it is a UTF-8
character (or any other character encoding for that matter)?
UIKit完全支持unicode,您的问题很可能是源文件的编码。您可以在检查器(Xcode 4:⌘⌥1)的“文本设置”下进行设置。确保它也是 UTF-8。
替代方案:使用 unicode 转义符,如
@"\u2605"
(应显示 ★)。UIKit fully supports unicode, your problem is most likely the encoding of the source file. You can set that in the inspector (Xcode 4: ⌘⌥1) under "Text Settings". Make sure it is UTF-8 as well.
Alternative: Use unicode escapes like
@"\u2605"
(should display ★).