您的位置:首页 > 产品设计 > UI/UE

iOS 运用富文本在UILabel上显示图片

2017-06-30 15:18 369 查看
NSMutableAttributedString * attrubedStr = [[NSMutableAttributedString
alloc]initWithString:[NSString
stringWithFormat:@"哈哈哈哈"]];

        

NSTextAttachment * attach = [[NSTextAttachment
alloc]init];

        

attach.image = [UIImage
imageNamed:@"moren"];

//图片位置       

attach.bounds =
CGRectMake(0,
0,
40, 15);

        

NSAttributedString *string = [NSAttributedString
attributedStringWithAttachment:attach];

        

//将图片放在最后一位    

[attri appendAttributedString:string];

//将图片放在第一位

//        [attri insertAttributedString:string atIndex:0];

NSTextAttachment * attach = [[NSTextAttachment
alloc]init];

self.nameLabel.attributedText =
attrubedStr;
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: