介绍
友盟的IM是支持自定义表情的,在友盟IM自定义表情包里面,是有一个淘公仔的表情包,为了我们可以自己添加自己的的表情包,我们先看一下友盟提供的淘公仔表情包的相关文件配置。
首先我们先看一下自定义表情所在的位置,我是直接在下载的SDK的Demo里面改的,在下面的代码里面实现自定义表情:
- (void)exampleShowCustomEmotionWithConversationController:(YWConversationViewController *)aConversationController
我们可以找到代码的位置:
找到这个YW_TGZ_Emoitons.emo的文件,复制一份将文件的后缀名改成.zip并解压,可以看到文件下的所有资源文件:
在这里面的有两个xml文件,config.xml 和 EmotionConfig.xml
config.xml 文件是整个表情包的资源配置文件的,
EmotionConfig.xml 文件是配置表情数据的,
我们看这两个标签
<OriginalFile> </OriginalFile> // 表情源图片文件用于表情消息发送,可以支持gif文件<FixedFile> </FixedFile> // 表情静态图片文件用于输入面板中表情的显示
TGZ目录下除了EmotionConfig.xml中配置的表情图片文件还有另外一张图片:
EmotionGroupIcon@2x.png :表情分组图标,用于输入面板底部表情分组的显示。
现在我们就可以自己实现一个自定义表情包了。。。。
自定义表情
准备好本地表情图片,最好将图片有序排列好,
修改config.xml和EmotionConfig.xml文件,可以将淘公仔里面的文件复制过来,修改一下就行了,
压缩文件,修改后缀名,这里不要直接压缩config.xml所在的文件夹,选中config.xml和haha目录进行压缩。命名好得到的压缩文件并把后缀名修改为emo,我们这里就叫haha.emo
将haha.emo拖进工程里面,添加如下代码
/*** 设置如何显示自定义表情*/* (void)exampleShowCustomEmotionWithConversationController:(YWConversationViewController *)aConversationController {if ([aConversationController.messageInputView isKindOfClass:[YWMessageInputView class]]) {YWMessageInputView *messageInputView = (YWMessageInputView *)aConversationController.messageInputView;for ( id item in messageInputView.allPluginList ){if ( ![item isKindOfClass:[YWInputViewPluginEmoticonPicker class]] ) continue;YWInputViewPluginEmoticonPicker *emotionPicker = (YWInputViewPluginEmoticonPicker *)item;// 淘公仔表情NSString *filePath = [[NSBundle mainBundle] pathForResource:@"YW_TGZ_Emoitons" ofType:@"emo"];NSArray *groups = [YWEmoticonGroupLoader emoticonGroupsWithEMOFilePath:filePath];for (YWEmoticonGroup *group in groups){[emotionPicker addEmoticonGroup:group];}// 自定义表情NSString *filePath1 = [[NSBundle mainBundle] pathForResource:@"haha" ofType:@"emo"];NSArray *newgroups = [YWEmoticonGroupLoader emoticonGroupsWithEMOFilePath:filePath1];for (YWEmoticonGroup *group in newgroups) {[emotionPicker addEmoticonGroup:group];}}}}
一切OK,运行程序,看到自定义的表情了