【问题标题】:NSMutableAttributedString contains NSMutableAttributedString and NSStringNSMutableAttributedString 包含 NSMutableAttributedString 和 NSString
【发布时间】:2014-04-25 07:20:58
【问题描述】:
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 上附加一个字符串,知道吗?

【问题讨论】:

  • 你试过追加吗?
  • @Wain 谢谢,我试过了,但其他一些问题使它显示错误,现在可以了。

标签: ios objective-c nsstring nsattributedstring


【解决方案1】:

尝试将 NSMutableAttributedString 的 appendAttributedString 用于您的属性字符串,如下所示

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];

希望对您有所帮助....!

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2013-10-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多