在Swift中将Unicode(例如1f564)转换为表情符号 [英] Convert Unicode (e.g. 1f564) to Emoji in Swift

查看:139
本文介绍了在Swift中将Unicode(例如1f564)转换为表情符号的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何将存储为字符串的unicode表情符号(例如 1f564 )转换为可放置在UILabel上的表情符号?

How do you convert unicode emoji stored as a string (e.g. 1f564) to an emoji that could be placed on a UILabel?

let myString = "1f564"

我已经看到使用转义字符,但我无法插入变量来替换字符。

I've seen the use of the escape character but I can't insert variables to replace the characters.

let flag = "\u{1f1e9}\u{1f1ea}"

谢谢

推荐答案

这有效。我不知道是否有更直接的东西:

This works. I don't know if there is anything more direct:

let myStr = "1f564"
let str = String(UnicodeScalar(Int(myStr, radix: 16)!)!)

这篇关于在Swift中将Unicode(例如1f564)转换为表情符号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆