Display emogi icon in unichar with string

605 views Asked by At

In my application i want to display emoji icon with string but its giving me syntax error.

It's displays below string successfully

unichar character = 0xE116;
self.uniCharStr =[NSString stringWithCharacters:&character length:1];

But its giving syntax error while i use value as following.

unichar character = &#x1f4a1
self.uniCharStr =[NSString stringWithCharacters:&character length:1];

I have get this values from emoji icon list from this link.

Can anyone please guide me where i m wrong ?

Thanks!

2

There are 2 answers

3
Adarsh V C On BEST ANSWER

Try \U0001F4A1 instead of &#x1f4a1

You should replace &#x withU000 also dont forget to add an escape sequence.

Edit :

To display the emoji in a label, I use the following code.

label.text = [NSString stringWithFormat:@"%@", @"\U0001f4a1"];
3
Muhammed Ayaz On

try this hope this will help you.

NSString *emojiStr  = [NSString stringWithFormat:@"(%@)", @"0xE116"];