在 Swift 中显示表情符号
Display Emoji in Swift
我从网络服务带回表情符号 unicode,例如U+1F601
如何在标签中显示它们?我可以从 unicode 值做到这一点吗?
我正在使用此列表中的 unicode:
你可以这样做:
UILabel *label = [[UILabel alloc] init];
label.font = [UIFont fontWithName:@"AppleColorEmoji" size:16.0];
label.text = [NSString stringWithFormat:@"%C", 0xe025];
您可以看到完整的编码列表here。
要将您获得的 unicode 转换为表情符号,可以这样做:
let myStr = "1f601"
let str = String(Character(UnicodeScalar(Int(myStr, radix: 16)!)))
我就是这样做的
lblTest.text = String(format: "%C", 0xe04f)
我从网络服务带回表情符号 unicode,例如U+1F601
如何在标签中显示它们?我可以从 unicode 值做到这一点吗?
我正在使用此列表中的 unicode:
你可以这样做:
UILabel *label = [[UILabel alloc] init];
label.font = [UIFont fontWithName:@"AppleColorEmoji" size:16.0];
label.text = [NSString stringWithFormat:@"%C", 0xe025];
您可以看到完整的编码列表here。
要将您获得的 unicode 转换为表情符号,可以这样做:
let myStr = "1f601"
let str = String(Character(UnicodeScalar(Int(myStr, radix: 16)!)))
我就是这样做的
lblTest.text = String(format: "%C", 0xe04f)