图文混排:
//图文混搭
NSMutableAttributedString *string = [[NSMutableAttributedString alloc] initWithAttributedString:textV.attributedText]; //获取textV原来的内容信息
fatieImage = [[FaTieImage alloc]init];
fatieImage.image = image;
NSAttributedString *textAttachmentString = [NSAttributedString attributedStringWithAttachment:fatieImage];
[string insertAttributedString:textAttachmentString atIndex:textV.selectedRange.location];
textV.attributedText = string;
[textV setFont:[UIFont fontWithName:@"Arial" size:16]];
[textV becomeFirstResponder];
查找图片:
//找出图片
NSRange range;
NSMutableArray *imgList=[[NSMutableArray alloc]init]; //图片个数
for (int i=0; i<textV.text.length; i++) {
NSDictionary *dic=[textV.attributedText attributesAtIndex:i effectiveRange:&range];
FaTieImage *img=dic[@"NSAttachment"]; //FaTieImage是继承NSTextAttachment的类
if (img) {
NSLog(@"有图片,位置是:%d",i);
img.location=i;
[imgList addObject:img];
}
}
这个方法有点笨,我在网上找了很久,没找到。自己写了个,先用着。