ios 如何在界面生成器的 UILabel 中输入 unicode 字符?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/11070428/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to enter unicode characters in a UILabel in Interface Builder?
提问by ragnarius
I would like to display a unicode character (the speaker symbol U+1F50A) in label. Is it possible to enter this symbol in Interface Builder?
我想在标签中显示一个 unicode 字符(扬声器符号 U+1F50A)。是否可以在 Interface Builder 中输入此符号?
回答by graver
Yes, you can click "Edit" > "Special Characters…" — there you can find all unicode characters (including the emoji) and copy/paste them where you set the label text in Interface Builder.
是的,您可以单击“编辑”>“特殊字符...”——在那里您可以找到所有 unicode 字符(包括表情符号)并将它们复制/粘贴到您在 Interface Builder 中设置标签文本的位置。
EDIT: In Xcode 6 it's "Edit" > "Emoji & Characters"
编辑:在 Xcode 6 中,它是“编辑”>“表情符号和字符”
Xcode 7+: "Edit" > "Emoji & Symbols"
Xcode 7+:“编辑”>“表情符号和符号”
回答by JohnVanDijk
For those who tried doing it programmatically, but failed, just use this:
对于那些尝试以编程方式执行但失败的人,只需使用以下命令:
label.text = @"\U0001F50A";
回答by Phillip
Do it programmatically.
以编程方式执行此操作。
Declare an IBOutlet for the Label, with the means of NSString type:
为 Label 声明一个 IBOutlet,方式为 NSString 类型:
// UTF-8 Hexadecimal Encoding
NSString *myString = [NSString stringWithUTF8String:"0xF09F948A"];
myLabel.text = myString;
Also, take a look at thisquestion.
另外,看看这个问题。
回答by leinadsey
In Xcode 8/Swift 3 the easiest is to use the unicode escape:
在 Xcode 8/Swift 3 中,最简单的方法是使用 unicode 转义:
let a = "\u{1F50A}"
回答by sVd
It's fun why few people knew this. You can enter Unicode-symbols directly by holding "Option" and entering hex digit. All you need: (Sierra example) goto "Preference -> Keyboards -> Input Sources" and search for "Unicode Hex". It should appears under "Others" section. Next add it and then you be able enter Unicode-char anywhere just selecting this input source.
有趣的是为什么很少有人知道这一点。您可以通过按住“Option”并输入十六进制数字来直接输入 Unicode 符号。您只需要:(Sierra 示例)转到“首选项 -> 键盘 -> 输入源”并搜索“Unicode Hex”。它应该出现在“其他”部分下。接下来添加它,然后你就可以在任何地方输入 Unicode-char 只需选择这个输入源。
For example: ? = (Alt+2713), - (20ac), etc. Most interesting section from 2100 to 2800. Full list you can found here - Unicode table
例如: ?= (Alt+2713)、- (20ac) 等。从 2100 年到 2800 年最有趣的部分。您可以在此处找到完整列表 - Unicode 表
P.S.: This method sutable only for four-digit Unicodes
PS:此方法仅适用于四位 Unicodes