标签:
// 1> Attachment - 附件
NSTextAttachment *attachment = [[NSTextAttachment alloc] init];
attachment.image = [UIImage imageNamed:@"d_aini"];
// 提示 lineHeight 大致和字体的大小相等
/**
面试题
请说出 frame 和 bounds 的区别
frame: x, y 决定当前控件,相对父控件的位置
bounds: x, y 决定内部子控件想对原点的位置,就是 scrollView 的 contentOffset!
*/
CGFloat height = self.label.font.lineHeight;
attachment.bounds = CGRectMake(0, -4, height, height);
// 2> 图像字符串
NSAttributedString *imageStr = [NSAttributedString attributedStringWithAttachment:attachment];
// 3> 定义一个可变的属性字符串
NSMutableAttributedString *attrStrM = [[NSMutableAttributedString alloc] initWithString:@"我"];
// 4> 拼接图片文本
[attrStrM appendAttributedString:imageStr];
[attrStrM appendAttributedString:[[NSAttributedString alloc] initWithString:@"88!"]];
// 设置属性文本
self.label.attributedText = attrStrM;
标签:
原文地址:http://www.cnblogs.com/kingtoKing/p/5658513.html