iOS 富文本图文混排 图片上下居中
作者:
PANZHI蜕变 | 来源:发表于
2020-07-23 14:36 被阅读0次 NSTextAttachment *attach = [[NSTextAttachment alloc] init];
attach.image = [UIImage imageNamed:@"img_icon"];
CGFloat paddingTop = label.font.lineHeight - label.font.pointSize;//获取顶边距离 使其居中
attach.bounds = CGRectMake(0, -paddingTop, 30, 30);
NSAttributedString *attStr = [NSAttributedString attributedStringWithAttachment:attach];
NSMutableAttributedString *abs = [[NSMutableAttributedString alloc] initWithString:label.text];
[abs insertAttributedString:attStr atIndex:0];
[abs appendAttributedString:attStr];
label.attributedText = abs;
本文标题:iOS 富文本图文混排 图片上下居中
本文链接:https://www.haomeiwen.com/subject/ruiclktx.html
网友评论