UILabel doesn't show emoji

I am having a problem displaying emoji in UILabel. I am getting this data from a web service (I cannot change the way I get the data): This value is relative to the debugger:

__NSCFString *  @"emoji \\ud83d\\ude1b\\ud83d\\ude1d"   0x000000017405ea80 

      

Value from NSLog:

emoji \ud83d\ude1b\ud83d\ude1d

      

if I assign this value to my text property UILabel, I get on screen:

emoji \ud83d\ude1b\ud83d\ude1d

      

I tried to encode and decode the string using:

NSData *data = [string dataUsingEncoding:NSNonLossyASCIIStringEncoding];
NSString *dataValue = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
return dataValue;

      

and when i try:

NSData *data = [string dataUsingEncoding:NSUTF8StringEncoding];
NSString *output = [[NSString alloc] initWithData:data encoding:NSNonLossyASCIIStringEncoding];

      

I am getting emoji on screen, but if the string does not contain emoji inside, it will be nil and get an empty label on the device.

I cannot get it to work correctly.

Thanks for any help.

+3


source to share


2 answers


I tried your code, the second ... and it works great:

Here's what I have:

enter image description here



and the output is:

enter image description here

deleting the emoji line \\ud83d\\ude1b\\ud83d\\ude1d

just leave emoji

. this is using a simulator, I am wondering that the error only appears on the device? while in the simulator does it work?

+1


source


Try to install UILabel

with



//Example
[NSString stringWithUTF8String:"\ud83d"]

      

0


source







All Articles