1

I want to override the method that draws the text into a UITextView. What is the correct method to override?

Peter DeWeese
  • 18,141
  • 8
  • 79
  • 101
aryaxt
  • 76,198
  • 92
  • 293
  • 442

2 Answers2

6

Update 2016-02-09: This answer is now wrong (and has been since iOS 6). You can now use UITextView by setting an NSAttributedString to the attributedText property instead of setting a normal NSString to the text property.

Relevant newer question: https://stackoverflow.com/a/14231900/458205


Original Answer

There's no way to set different colours for different words in a UITextView.

There are multiple replacements for a UITextView which support rich text editing (listed bellow). However if you only want to give different text different color's in a UITextView (like syntax highlighting) the easiest thing to do is just use a UITextView itself for the editing with a CoreText overlay displaying the coloured text.

https://github.com/SquaredTiki/EditableCoreTextOverlay

Community
  • 1
  • 1
Kyle Howells
  • 3,008
  • 1
  • 25
  • 35
1

Multiple colors in a UITextView is not possible at this point in time. You can set one text color only.

If you need multiple text colors, the only way is loading a RTF file in a UIWebView, but that doesn't allow editing.

Maybe in iOS 5 there'll be RTF support for UITextView.

Pripyat
  • 2,937
  • 2
  • 35
  • 69
  • that's not correct I've seen libraries that do this, but I want to write my own – aryaxt Jul 01 '11 at 20:41
  • I think you're getting mixed up between the meanings of `library` and `subclass`...? There're some subclasses that can do this to a limited extent on GitHub, but `UITextView` cannot. – Pripyat Jul 03 '11 at 09:39