ios7 获取TextView中图片信息。

图文混排:

    //图文混搭
    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
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值