Wednesday, February 10, 2010

How to Put a Smiley Into Your UILabel

Sometimes iPhone SDK just makes you smile, things you expect to be difficult turn out to be really simple. Take for example a smiley face :)
NSRange range = {NSNotFound, 0};
NSString *s = @"This is a smiley :) face";

range.location = 0;
range.length = [s length];
s = [s stringByReplacingOccurrencesOfString:@":)"
withString:@"\ue415"
options:NSCaseInsensitiveSearch
range:range];

iPhone contains by default a Japanese font, which supports unicode emoji characters. As a result you suddenly have built-in supports for about 460 graphical icons, all of which you can put anywhere as part of any text string!

Here's full list of emoji characters in iPhone. Have fun ;)

2 comments:

  1. Hi,
    Thanks a million. This is what I have been looking for a month.
    cheers

    ReplyDelete
  2. HI,
    for me It is not working ,it's showing yes like this.
    Is there need to add any framework?
    please help

    ReplyDelete