iphone - 无法将 NSString 传递到 NSMutableAttributedString 中?

标签 iphone objective-c core-text nsattributedstring

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

相关文章:

iphone - 如何使用 CATransform3DRotate 旋转 UIImageView 做出类似开门的效果?

iphone - 使用2G,3G,4G网络的iPhone应用程序

objective-c - 如何调整 NSImage 的大小?

iphone - 生成适合 iPhone 查看大小的 PDF

ios - CTFrame 有时为空,具体取决于 UIFont pointSize

iphone - 来自文本的 CGPathRef

iphone - 如何使用 iOS 上的原生 Twitter 应用程序打开 Twitter 推文?

ios - 为什么要使用委托(delegate)?

cocoa - NSTextView 的疯狂字体问题

iphone - 程序接收到信号 EXC BAD ACCESS