首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >NSMutableAttributedString包含NSMutableAttributedString和NSString

NSMutableAttributedString包含NSMutableAttributedString和NSString
EN

Stack Overflow用户
提问于 2014-04-25 07:20:58
回答 1查看 1.3K关注 0票数 1
代码语言:javascript
复制
NSTextAttachment *attachment = [[NSTextAttachment alloc] init];
attachment.image = [UIImage imageNamed:@"smiley_0.png"];
attachment.bounds = CGRectMake(0, 0, 22, 22);
NSMutableAttributedString *attributedString = [[NSAttributedString attributedStringWithAttachment:attachment] mutableCopy];
[aLabel setAttributedText:attributedString];

使用上面的代码,aLabel可以正确地显示图像(smiley_0.png),现在我想给aLabel添加一个字符串,有什么想法吗?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2014-04-25 07:32:44

尝试将appendAttributedString of NSMutableAttributedString用于attributedString,如下所示

代码语言:javascript
复制
NSTextAttachment *attachment = [[NSTextAttachment alloc] init];
attachment.image = [UIImage imageNamed:@"smiley_0.png"];
attachment.bounds = CGRectMake(0, 0, 22, 22);
NSMutableAttributedString *appendedString=[[NSMutableAttributedString alloc]initWithString:@"yourString"];
NSMutableAttributedString *attributedString = [[NSAttributedString attributedStringWithAttachment:attachment] mutableCopy];
[attributedString appendAttributedString:appendedString];
[aLabel setAttributedText:attributedString];

希望它能帮你.!

票数 3
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/23286629

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档