Pergunta

Is it possible to underline or embolden certain bits of text in a UITextView?

For example my Text View has headings in it, and would like those underlined...

Random Mode
In random mode, you can generate numbers...

Sweepstake Mode
In sweepstake mode...

If not, what is the best way to achieve this?

Thanks

Foi útil?

Solução

Use should use NSAttributedString, and use controllers for drawing NSAttributesString.

Controller for NSAttributedString

Note: you can't use UITextView to display a NSAttributedString

Update

From iOS6, UILabel now support NSAttributedString, you should use UILabel directly instead of OHAttributedLabel as it is now natively supported by the OS.

Outras dicas

I believe NSAttributedString is what you're after, it's available in iOS 3.2 or later: look at this question

I know this is an old thread, but this is something I just discovered myself. At least in Xcode version 4.6.3 this is possible by using an attributed textView. What's even better is that it's possible to all be done in Interface Builder!

Here are the steps:

  1. Place your textView at the desired location
  2. Select the textView and open up the Attributes tab under the Utilities panel
  3. Change the textView text to "attributed"
  4. Enter your desired text
  5. Now, highlight whatever text you want bolded, underlined, etc.
  6. Click on the "T" button next to the fontName
  7. In the popup, select your desired typeface (ex: Bold)
  8. You should see the desired typeface displayed in the Utilities panel

Enjoy!

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top