ChatGPT解决这个技术问题 Extra ChatGPT

How to enter unicode characters in a UILabel in Interface Builder?

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?

In addition to technical issues in entering the symbol, consider how widely it can be expected to work. According to fileformat.info/info/unicode/char/1f50a/fontsupport.htm the only font that supports it is Symbola. There might be some other fonts, specific to iPhone for example, that support it. But the character is very new, introduced in Unicode 6.0.
+1 Yes, the system font only has a bitmap of a speaker...

s
shim

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.

EDIT: In Xcode 6 it's "Edit" > "Emoji & Characters"

Xcode 7+: "Edit" > "Emoji & Symbols"


Yes, it works if I search for "speaker". But the symbol seams to be a bitmap and not a true font...
You can right-click on it and click Copy Characted Info, when you paste it you get the actual symbol (with some additional data)...
it's now called Edit > Emoji & Characters in Xcode 6.
And again, now it's called Edit > Emoji & Symbols in Xcode 7.3
important to know if you're not used to typing literal unicode characters into the Emoji & Characters window: you type 0x followed by the code, so if the unicode is f19c, you type 0xf19c into the search bar, and if it's supported by default, the character will come up, otherwise an empty box character will come up -- that empty box character is your unicode character, double click to insert
J
JohnVanDijk

For those who tried doing it programmatically, but failed, just use this:

label.text = @"\U0001F50A";

please make sure to use lower u and not upper U i.e. @"\u0001F50A"
No. Stick to upper U. When I tried this in Xcode 8.3 it spat out compiler error "Universal character name refers to a control character". I've test upper U and can confirm it works great.
p
pkamb

Do it programmatically.

Declare an IBOutlet for the Label, with the means of NSString type:

// UTF-8 Hexadecimal Encoding
NSString *myString = [NSString stringWithUTF8String:"0xF09F948A"];

myLabel.text = myString;

Also, take a look at this question.


+1, but it does not work for the specific symbol. According to fileformat.info/info/unicode/char/1f50a/index.htm I should enter the string "\uD83D\uDD0A". But Xcode says the symbol is invalid
Uhm, then try to use a string and assign it to the label. I'll edit my post
Sorry, now the label becomes 0xF09F948A .
Right. Well then i suggest to use a small UIImageView with the speaker, if you can put it.
l
leinadsey

In Xcode 8/Swift 3 the easiest is to use the unicode escape:

let a = "\u{1F50A}"  

s
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.

For example: ✓ = (Alt+2713), € - (20ac), etc. Most interesting section from 2100 to 2800. Full list you can found here - Unicode table

P.S.: This method sutable only for four-digit Unicodes


One thing to point out. The option key trick only works while you have the Unicode Hex input source selected.
If you're using IcoMoon.ttf fonts inside your project (to embed icons) that's the more comfortable answer I've found, specially when you have to type particular unicode entrypoints defined in your icomoon set. Even though in the IB right panel textfield a [?] symbol will appear, inside the IB "XIB zone" the actual character will actually appear.