DWIMFaceView_IOS 是IM對話中有表情輸入和對話框表情顯示

jopen 8年前發布 | 14K 次閱讀 iOS開發 移動開發 DWIMFaceView

DWIMFaceView

IOSIMFaceView 是IM對話中有表情輸入和對話框表情顯示。

Preview

image

Instructions

Face文件在expression中

//轉移字符開頭符號,可以是/s或者/.等。。

#define FACE_NAME_HEAD  @"["
// 表情轉義字符的長度( /s占2個長度,xxx占3個長度,共5個長度 )
#define FACE_NAME_LEN   5</pre> </div>

Usage

文本插入表情主要代碼:

EmojiTextAttachment *attachment = [[EmojiTextAttachment alloc]init];
    attachment.emojiSize = 20;
    UIImage *image = [UIImage imageNamed:[emojiTagname objectAtIndex:i]];
    attachment.image = image;
    NSAttributedString *text = [NSAttributedString attributedStringWithAttachment:attachment];
    [str replaceCharactersInRange:range withAttributedString:text];

輸入框插入表情主要代碼:

EmojiTextAttachment *emojiTextAttachment = [EmojiTextAttachment new];

//Set tag and image
emojiTextAttachment.emojiTag = emojiTags[tag];
emojiTextAttachment.image = [UIImage imageNamed:emojiTagname[tag]];

//Set emoji size
emojiTextAttachment.emojiSize = 20;

//Insert emoji image
[_contentText.textStorage insertAttributedString:[NSAttributedString attributedStringWithAttachment:emojiTextAttachment]
                                      atIndex:_contentText.selectedRange.location];

//Move selection location
_contentText.selectedRange = NSMakeRange(_contentText.selectedRange.location + 1, _contentText.selectedRange.length);

[self textViewDidChange:_contentText];</pre> </div>

項目地址: https://github.com/DavidWangTM/DWIMFaceView

 本文由用戶 jopen 自行上傳分享,僅供網友學習交流。所有權歸原作者,若您的權利被侵害,請聯系管理員。
 轉載本站原創文章,請注明出處,并保留原始鏈接、圖片水印。
 本站是一個以用戶分享為主的開源技術平臺,歡迎各類分享!