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