11

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!
DomMaiocchi
  • 2,737
  • 4
  • 17
  • 5
  • You can also use the OHAttributedLabel class, you can [find it here](https://github.com/AliSoftware/OHAttributedLabel/). HTH – AliSoftware Jun 17 '11 at 19:05

4 Answers4

2

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

defvol
  • 14,392
  • 2
  • 22
  • 32
2

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

Alex Zak
  • 1,924
  • 2
  • 18
  • 26
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)

mattt
  • 19,544
  • 7
  • 73
  • 84
1

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.

Joshua Nozzi
  • 60,946
  • 14
  • 140
  • 135
  • I'll be sure to file a bug report. Could you please point me in the direction of an example or tutorial of using Core Text to display an attributed string? Thanks :) – DomMaiocchi Sep 03 '10 at 16:31
  • 1
    A simple two-second search provides a few answers on this site alone: http://stackoverflow.com/questions/2446975/core-text-examples-for-iphone-ipad – Joshua Nozzi Sep 03 '10 at 17:23