NSMutableAttributedString

NSMutableAttributedString

我想创建一个显示标题,子标题,嵌入的图像和常规文本(有点类似于Wikipedia样式页面)的显示。我的标题,子标题,图像和常规文本都以字符串形式存在。我知道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/

10-11 01:22