Chris Ellingsworth
Chris Ellingsworth

Reputation: 85

Having trouble getting correct unicode symbol to show

I'm using http://symbolset.com for icons in my iOS app and haven't been able to get the camera symbol to show correctly. In the symbolset docs and in FontForge, it says the unicode value is 1F4F7.

Here's the relevant code:

[self setTitle:[NSString stringWithFormat:@"%C", (unichar)0x1F4F7] forState:controlState];

I also tried:

[self setTitle:[NSString stringWithFormat:@"%C", (unichar)0x0001F4F7] forState:controlState];

However this works for the check mark symbol:

[self setTitle:[NSString stringWithFormat:@"%C", (unichar)0x2713] forState:controlState];

The font is open type. I've also tried putting the unicode value in my Localizable.strings file, but that hasn't worked. Do I need to make it a TrueType font?

Update: I've tried converting to a TrueType font and have the same issue.

Upvotes: 0

Views: 876

Answers (1)

Wevah
Wevah

Reputation: 28242

The issue is that a unichar is only 16 bits, but the character that you want is outside of the basic multilingual plane (BMP) and so takes 2 characters in UTF-16 (a surrogate pair). You can either figure out the pair, or do something like:

UTF32Char c = 0x1F4F7;
NSData *utf32Data = [NSData dataWithBytes:&c length:sizeof(c)];
NSString *camera = [[NSString alloc] initWithData:utf32Data encoding:NSUTF32LittleEndianStringEncoding];

//do stuff with camera here and release if not using ARC

Upvotes: 3

Related Questions