开发者

How do I display a NSAttributedString on an iPhone? [duplicate]

This question already has answers here: 开发者_运维知识库 iphone/ipad: How exactly use NSAttributedString? (9 answers) Closed 9 years ago.

I believe I understand how to set NSAttributedString values but how on earth do you actually display them in the interface?

examples: UILabel, UITextView, etc.

Specific instructions would be greatly appreciated/

  • Thanks!


you could also create a CATextLayer, which works fine with attributed strings... Just create the layer, and set it's string property...

Have fun... :D


If you don't want to bother with CATextLayer, you should check out TTTAttributedLabel. It's just like UILabel, except that supports NSAttributedStrings (using the same setText: method as UILabel, so you can use it as a drop-in replacement)


In iOS 6 and later you can use attributed strings to display formatted text in text views, text fields, and some other controls. Both AppKit and UIKit also define extensions to the basic attributed string interface that allows you to draw their contents in the current graphic context.

NSAttributedString Reference


The controls you mentioned only work with strings, not attributed strings. The only way to display them is to do a lot of work with Core Text. File a complaint with bugreporter.apple.com to request they flesh this part of UIKit out.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜