iOS 富文本文字添加图片

如图:标题前面添加海外直邮和跨境保税,iOS最好使用富文本添加图片附件的方法

 

NSTextAttachment*textAttachment = [[NSTextAttachment alloc] init];
//给附件添加图片
textAttachment.image= [UIImage imageNamed:@"trc_mall_overseas_directmail"];
//调整一下图片的位置,如果你的图片偏上或者偏下,调整一下bounds的y值即可
textAttachment.bounds=CGRectMake(0, -4, textAttachment.image.size.width, textAttachment.image.size.height);
//把附件转换成可变字符串,用于替换掉源字符串中的表情文字        
NSAttributedString*imageStr = [NSAttributedString attributedStringWithAttachment:textAttachment];
[m_attributedString appendAttributedString:imageStr];

 

 

 

转载于:https://my.oschina.net/zhuzhu1223/blog/906464

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值