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

◇◆丶佛笑我妖孽 提交于 2019-12-05 15:47:06

问题


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!

回答1:


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




回答2:


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)




回答3:


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




回答4:


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.



来源:https://stackoverflow.com/questions/3637631/how-do-i-display-a-nsattributedstring-on-an-iphone

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!