php图文混排编辑,iOS 富文本之图文混排之编辑

插入图片,上传服务器 看这里

直接上代码了。

1.把需要编辑的内容里面的照片过滤出来

- (NSArray *) getImageurlFromHtml:(NSString *) webString

{

NSMutableArray * imageurlArray = [NSMutableArray arrayWithCapacity:1];

//标签匹配

NSString *parten = @"";

NSError* error = NULL;

NSRegularExpression *reg = [NSRegularExpression regularExpressionWithPattern:parten options:0 error:&error];

NSArray* match = [reg matchesInString:webString options:0 range:NSMakeRange(0, [webString length] - 1)];

for (NSTextCheckingResult * result in match) {

//获取数组中的标签

NSRange range = [result range];

NSString * subString = [webString substringWithRange:range];

//从图片中的标签中提取ImageURL

NSRegularExpression *subReg = [NSRegularExpression regularExpressionWithPattern:@"http://[^'|\"|\\s|>]*" options:0 error:NULL];

NSArray* match = [subReg matchesInString:subString options:0 range:NSMakeRange(0, [subString length] - 1)];

NSTextCheckingResult * subRes = match[0];

NSRange subRange = [subRes range];

subRange.length = subRange.length ;

NSString * imagekUrl = [subString substringWithRange:subRange];

//将提取出的图片URL添加到图片数组中

[imageurlArray addObject:imagekUrl];

}

return imageurlArray;

}

2.因为把html 转成富文本(转完之后 图片attechment里面的userinfo是空的),所以需要给userinfo附上值,也就是上面获取的image

- (void)handlerAllAttechmentWith:(NSAttributedString *)StringString withimagesArr:(NSArray *)imageUrl{

NSMutableArray *attachmentArr=[NSMutableArray array];

NSRange effectiveRange = NSMakeRange(0, 0);

while (effectiveRange.location + effectiveRange.length < StringString.length) {

NSDictionary *attributes = [StringString attributesAtIndex:effectiveRange.location effectiveRange:&effectiveRange];

NSTextAttachment *attachment = attributes[@"NSAttachment"];

if (attachment) {

[attachmentArr addObject:attachment];

}

effectiveRange = NSMakeRange(effectiveRange.location + effectiveRange.length, 0);

}

if (attachmentArr.count == imageUrl.count) {

for (int i=0; i

NSTextAttachment *att=attachmentArr[i];

//userinfo这个属性是延展,看上一篇

att.userInfo= imageUrl[i];

}

}

}

3.接下来的操作,按照插入图片,上传服务器走就可以。

在这里,只是简单实现图片的更换,文字的修改。涉及到字体大小,颜色等操作,后期慢慢加入。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值