gpt4 book ai didi

ios - NSMutableAttributedString包含NSMutableAttributedString和NSString

转载 作者:行者123 更新时间:2023-12-01 19:00:27 33 4
gpt4 key购买 nike

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后面附加一个字符串,有什么想法吗?

最佳答案

尝试如下使用NSMutableAttributedString的appendAttributedString到您的attributedString

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

希望它能对您有所帮助。

关于ios - NSMutableAttributedString包含NSMutableAttributedString和NSString,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23286629/

33 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com