实现效果:新闻列表标题,在标题最后一个字符加已读未读标签。
用富文本标签实现的,在富文本标签里面添加文本附件图片插入到文本最后中,这样无论是几行图片都会显示的标题最后一个字符后面。
+ (NSAttributedString *)stringInsertImageWithImageName:(NSString *)imageName imageReact:(CGRect)imageReact insertIndex:(NSInteger)insertIndex content:(NSString *)content stringColor:(UIColor *)stringColor stringFont:(UIFont *)stringFont{
//创建富文本
NSMutableAttributedString *attributedStr = [[NSMutableAttributedString alloc]initWithString:content];
//修改富文本中的文字样式文本颜色
[attributedStr addAttribute:NSForegroundColorAttributeName value:stringColor range:NSMakeRange(0, content.length)];
//文本大小
[attributedStr addAttribute:NSFontAttributeName value:stringFont range:NSMakeRange(0,content.length)];
//创建文本附件图片 插入到富文本中
NSTextAttachment *attchImage = [[NSTextAttachment alloc]init];
attchImage.image = [UIImage imageNamed:imageName];
attchImage.bounds = imageReact;
NSAttributedString *stringImage = [NSAttributedString attributedStringWithAttachment:attchImage];
//[attriStr appendAttributedString:stringImage];//在文字最后添加图片
//图片插入位置
[attributedStr insertAttributedString:stringImage atIndex:insertIndex];
return attributedStr;
}