iOS-环信自定义聊天气泡


其实自定义环信的聊天气泡并没有想象中那么麻烦,归根到底只需要三步就能完成,记录一下自己的一个思路。

1.写一个BubbleView的类,可参考环信自带的类,只要是做一些约束的工作,如下。

2.为BubbleView分配一个Identifier,也可参考环信自带的Identifier的写法,如下

extern NSString *const EaseMessageCellIdentifierSendText;
extern NSString *const EaseMessageCellIdentifierSendLocation;
extern NSString *const EaseMessageCellIdentifierSendVoice;
extern NSString *const EaseMessageCellIdentifierSendVideo;
extern NSString *const EaseMessageCellIdentifierSendImage;
extern NSString *const EaseMessageCellIdentifierSendFile;
extern NSString *const EaseMessageCellIdentifierSendImageText;

extern NSString *const EaseMessageCellIdentifierRecvText;
extern NSString *const EaseMessageCellIdentifierRecvLocation;
extern NSString *const EaseMessageCellIdentifierRecvVoice;
extern NSString *const EaseMessageCellIdentifierRecvVideo;
extern NSString *const EaseMessageCellIdentifierRecvImage;
extern NSString *const EaseMessageCellIdentifierRecvFile;
extern NSString *const EaseMessageCellIdentifierRecvImageText;

3.在bodyType的类型里做判断显示,如下

            case EMMessageBodyTypeText:
            {
                if (model.message.ext == nil) {
                    [_bubbleView setupTextBubbleView];
                    
                    _bubbleView.textLabel.font = _messageTextFont;
                    _bubbleView.textLabel.textColor = _messageTextColor;
                } else {
                    [_bubbleView setupImageTextBubbleView];
                    
                    _bubbleView.fileNameLabel.font = _messageFileNameFont;
                    _bubbleView.fileNameLabel.textColor = _messageFileNameColor;
                    _bubbleView.fileSizeLabel.font = _messageFileSizeFont;

                }
                
            }
                break;

 好多时候,环信已经做好很多工作,我们只需要跟着它的步骤一步一步做下去就行了。

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM