9

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?

James
  • 6,471
  • 11
  • 59
  • 86

2 Answers2

18

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.

lqs
  • 1,434
  • 11
  • 20
  • Sure that this is allowed for ios? Afaik only 16 bits are implemented. – iOS Oct 27 '12 at 16:27
  • @iOS: NSString handles (at least at the API level) UTF-16 code units. UTF-16 can represent code points greater than U+FFFF using a system called surrogates. I elaborate in a blog post from a few months ago: http://boredzo.org/blog/archives/2012-06-03/characters-in-nsstring – Peter Hosey Oct 27 '12 at 18:25
  • Thanks for the link, that was my missing bit to understand that UTF-16 has a method to extend the points beyond 16 bits. – iOS Oct 27 '12 at 18:31
-1

In iOS unicode characters belong to a 16bit representation \u , with n between 0000 and ffff in hexadecimal notation.

In your example \uF601 represents one character and you could add another character by adding another sequence \uF601\uF602 etc.

For me it seems that you misunderstood the escape syntax?

iOS
  • 813
  • 5
  • 14
  • Those would be two consecutive characters, not the single character (U+1F4E5) the questioner wants. – Peter Hosey Oct 27 '12 at 16:55
  • Right that was what i mentioned with "adding another sequence". Which I thought was requested by "4 characters" in the question. Interesting thing that a symbol font with only 460 characters has to use more than 16 bits. – iOS Oct 27 '12 at 16:58
  • My reading of “4 characters” was “4 digits” (note the number of hex digits after the `\u` in each example). As for the font, it's not how many characters it has glyphs for; it's which code points it uses them for. – Peter Hosey Oct 27 '12 at 18:13