用twitter开源twemoji替换iOS app表情符号 [英] Replace iOS app emoji with twitter open source twemoji

查看:313
本文介绍了用twitter开源twemoji替换iOS app表情符号的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用twitters开源



最后,我得出了与你相同的结论:


我找不到任何要做的库或文档这在iOS中。




所以,我创建了 Swift中的一个框架,用于此目的。



它为您完成所有工作,但如果您想要实现如下所示,我将在下面介绍如何用Twemoji替换所有标准表情符号。






< H3> 1。记录可以表示为表情符号的所有字符

有1126个基本字符具有表情符号表示,以及由序列形成的超过一千个其他表示。虽然大多数基本字符仅限于六个 Unicode块,但除了其中一个块之外的所有块都混合了非表情符号字符和/或未分配的代码点。这些块之外的其余基本字符分散在其他各个块中。



我的实现只是声明这些字符的UTF-32代码点,如 的属性UnicodeScalar 就是这样。



2。检查字符是否为表情符号



在Swift中,字符串包含的集合字符对象,每个对象代表一个扩展的字形集群。扩展字形集群是一系列Unicode标量,它们共同代表一个 1 人类可读字符,这很有用,因为您可以遍历字符字符串的s并根据它们包含的 UnicodeScalar 处理它们(而不是循环遍历字符串的UTF-16值)。



确定字符是否为一个表情符号,只有第一个 UnicodeScalar 是重要的,所以将这个值与表情符号字符表进行比较就足够了。但是,我还建议检查字符是否包含变体选择器,如果确实如此,请确保它是VS16 - 否则该字符不应显示为表情符号。



提取来自字符 UnicodeScalar 需要一个小小的黑客:

 让c:字符=A
让scalars = String(c).unicodeScalars



3。将代码点转换为正确的格式



Twemoji 图像根据它们对应的代码点 2 命名,这是有道理的。因此,下一步是将字符转换为与图像名称等效的字符串:

 让codePoint = String(

I want to replace all standard iOS emoji from a UILable or UITextView with twitters open source twemoji.

I can't find any library or documentation to do this in iOS. Does anyone have a solution that does not involve me implementing this from scratch?

The solution needs to be efficient and work offline.

解决方案

The question got me intrigued, and after a bit of searching on how it would be possible to replace all standard iOS emoji with a custom set, I noticed that even Twitter's own iOS app doesn't use Twemoji:

In the end, I came to the same conclusion as you:

I can't find any library or documentation to do this in iOS.

So, I created a framework in Swift for this exact purpose.

It does all the work for you, but if you want to implement your own solution, I'll describe below how to replace all standard emoji with Twemoji.


1. Document all characters that can be represented as emoji

There are 1126 base characters that have emoji representations, and over a thousand additional representations formed by sequences. Although most base characters are confined to six Unicode blocks, all but one of these blocks are mixed with non-emoji characters and/or unassigned code points. The remaining base characters outside these blocks are scattered across various other blocks.

My implementation simply declares the UTF-32 code points for these characters, as the value property of UnicodeScalar is exactly this.

2. Check whether a character is an emoji

In Swift, a String contains a collection of Character objects, each of which represent a single extended grapheme cluster. An extended grapheme cluster is a sequence of Unicode scalars that together represent one1 human-readable character, which is helpful since you can loop through the Characters of a string and handling them based on the UnicodeScalars they contain (rather than looping through the UTF-16 values of the string).

To identify whether a Character is an emoji, only the first UnicodeScalar is significant, so comparing this value to your table of emoji characters is enough. However, I'd also recommend checking if the Character contains a Variation Selector, and if it does, make sure that it's VS16 – otherwise the character shouldn't be presented as emoji.

Extracting the UnicodeScalars from a Character requires a tiny hack:

let c: Character = "A"
let scalars = String(c).unicodeScalars

3. Convert the code points into the correct format

Twemoji images are named according to their corresponding code points2, which makes sense. So, the next step is to convert the Character into a string equivalent to the image name:

let codePoint = String("
                        

这篇关于用twitter开源twemoji替换iOS app表情符号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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