I want to override the method that draws the text into a UITextView. What is the correct method to override?
-
2It'd help a lot if you stated the actual problem and what you aim to achieve. This reads like your proposed solution :) – InsertWittyName Jul 01 '11 at 18:06
-
I am trying to override this method to change the style of the text I am trying to draw. So let's say draw text with multiple colors – aryaxt Jul 01 '11 at 18:09
-
1You can draw text with different colors by setting the `textColor` property? – Pripyat Jul 01 '11 at 18:10
-
@David no you can't that allows only 1 style for the whole text – aryaxt Jul 01 '11 at 18:12
2 Answers
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.

- 1
- 1

- 3,008
- 1
- 25
- 35
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
.

- 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