http://blog.sina.com.cn/s/blog_6f1a34260101ptox.html
更详细的文章:http://www.cocoachina.com/industry/20131028/7250.html
Textkit是iOS7新推出的类库,其实是在之前推出的CoreText上的封装,有了这个TextKit,以后不用再拿着CoreText来做累活了,根据苹果的说法,他们开发了两年多才完成,而且他们在开发时候也将表情混排作为一个使用案例进行研究,所以要实现表情混排将会非常容易。
@interface MMTextAttachment : NSTextAttachment
@end
NSMutableAttributedStrin g
* string = [[
NSMutableAttributedStrin galloc
] initWithString:@
"123456789101112"
attributes:
nil
] ;
MMTextAttachment* textAttachment = [[ MMTextAttachment alloc ]initWithData:
nil
ofType:
nil
] ;
UIImage* smileImage = [ UIImage imageNamed:@
"a.jpg"
] ;
//myemoticon image named a.jpg
textAttachment.image= smileImage ;
NSAttributedString
* textAttachmentString = [
NSAttributedString
attributedStringWithAtta chment:textAttachment ] ;
[string insertAttributedString:textAttachmentString atIndex:6 ];
_textView.attributedText= string ;