ios7 获取TextView中图片信息。

来源:互联网 发布:小学生编程比赛 编辑:程序博客网 时间:2024/06/03 16:54

图文混排:

    //图文混搭    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];        }    }
这个方法有点笨,我在网上找了很久,没找到。自己写了个,先用着。


0 0
原创粉丝点击