美文网首页iosiOS_UIKit
NSTextAttachment图文混排

NSTextAttachment图文混排

作者: 絮语时光杨 | 来源:发表于2018-05-10 16:54 被阅读0次

UILabel *lable = [[UILabel alloc]initWithFrame:CGRectMake(0, 150, 300, 21)];
//富文本
NSString *message = @"我是郝高明,外号小胖,哈哈~";
NSMutableAttributedString *str = [[NSMutableAttributedString alloc]initWithString:message attributes:@{NSFontAttributeName:[UIFont systemFontOfSize:16]}];

NSTextAttachment *attachment = [[NSTextAttachment alloc]initWithData:nil ofType:nil];  
UIImage *image = [UIImage imageNamed:@"80.png"];  
attachment.image = image;  
attachment.bounds = CGRectMake(0, 0, 20, 20);  
  
NSAttributedString *text = [NSAttributedString attributedStringWithAttachment:attachment];  
[str insertAttributedString:text atIndex:5];  
  
lable.attributedText = str;  

相关文章

网友评论

    本文标题:NSTextAttachment图文混排

    本文链接:https://www.haomeiwen.com/subject/rthtdftx.html