1. 图文混排示例
// 1. 文字部分
NSString *tempString1 = @"绑定手机号 " ;
NSMutableAttributedString *attributedString = [[NSMutableAttributedString alloc] initWithString:tempString1];
NSMutableParagraphStyle *paragraphStyle = [[NSMutableParagraphStyle alloc] init];
paragraphStyle.lineSpacing = THHomeShowContentLineSpacing; //调整行间距
paragraphStyle.alignment = NSTextAlignmentLeft;
[attributedString addAttributes:@{NSForegroundColorAttributeName : XLHexColor(THMainLightBlueColor) , NSFontAttributeName : XLSystemFont(12) ,NSParagraphStyleAttributeName : paragraphStyle} range:NSMakeRange(0, tempString1.length)];
// 2. 添加表情
NSTextAttachment *attchment = [[NSTextAttachment alloc] init];
// 表情图片
attchment.image = [UIImage imageNamed:@"btn_go"];
// 设置图片大小 以及xy的偏移量 , 注意一点y是负值的时候,图片位置往下偏移
attchment.bounds = CGRectMake(0, -20, 10, 10);
[attributedString appendAttributedString:[NSAttributedString attributedStringWithAttachment:attchment]];
NSAttributedString *attributedString2 = [[NSAttributedString alloc] initWithString:@" 绑定支付宝" attributes:
@{NSForegroundColorAttributeName : XLHexColor(THMainLightBlueColor) , NSFontAttributeName : XLSystemFont(12) ,NSParagraphStyleAttributeName : paragraphStyle}
];
[attributedString appendAttributedString:attributedString2];
indicatorLabel.attributedText = attributedString;