我想创建一个显示标题、子标题、嵌入图像和常规文本(有点类似于维基百科样式页面)的显示。我的标题、副标题、图像和常规文本都在字符串中。我知道 AttributedString 是实现我想要的格式的最佳方式。我不知道如何从我预先存在的字符串创建 AttributedString。
displayText = [[NSMutableAttributedString alloc] initWithAttributedString:@"%@ \n %d - %@", self.currentInstance.name, self.currentInstance.number, self.currentInstance.image];
textView.attributedText = displayText;
我是新来的,所以我确信我做错了一些基本的事情。我感谢任何帮助。
最佳答案
尝试
displayText = [[NSMutableAttributedString alloc] initWithString:[NSString stringWithFormat:@"%@",str]];
然后添加您的属性(我可能有拼写错误,因为我在评论框中输入了此内容,但这应该可行。
关于iphone - 无法将 NSString 传递到 NSMutableAttributedString 中?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18087325/