Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Writing a unicode character with NSString

Tags:

ios

cocoa

I'm using the symbol font Symbolicons instead of images in a new project. However, it seems that any code over 4 characters can't be set using NSString.

Example:

self.saveDealButton.titleLabel.font = [UIFont fontWithName:@"SS Symbolicons" size:31.0f];
[self.saveDealButton setTitle:@"\u1F4E5" forState:UIControlStateNormal];

Will not work, however:

self.shareButton.titleLabel.font = [UIFont fontWithName:@"SS Symbolicons" size:31.0f];
[self.shareButton setTitle:@"\uF601" forState:UIControlStateNormal];

Works fine. How can I get NSString to recognize the extra bit?

like image 652
James Avatar asked Oct 27 '12 15:10

James


People also ask

How do you write a character in Unicode?

Inserting Unicode characters To insert a Unicode character, type the character code, press ALT, and then press X. For example, to type a dollar symbol ($), type 0024, press ALT, and then press X.

How do I write Unicode characters in Linux?

In X11 (Linux and other Unix variants including Chrome OS) In many applications one or both of the following methods work to directly input Unicode characters: Holding Ctrl + ⇧ Shift and typing u followed by the hex digits, then releasing Ctrl + ⇧ Shift .

Can you create your own Unicode?

These days, an organization called the Unicode Consortium maintains the standard set of emoji used by apps and platforms, and now counts more than 2,700 characters in Version 11 of the set, with more on the way. But if you don't see the exact character you need in the current bunch, yes, you can create your own.

What is a Unicode example?

Unicode supports more than a million code points, which are written with a "U" followed by a plus sign and the number in hex; for example, the word "Hello" is written U+0048 U+0065 U+006C U+006C U+006F (see hex chart).


1 Answers

For those characters in the Supplementary Multilingual Plane, as in your example, use the uppercase U in the escape string and followed by eight hex code. So it should be written as \U0001F4E5.

like image 169
lqs Avatar answered Oct 28 '22 05:10

lqs