Wednesday, March 30, 2011

How to Change UITextView Background Color

You have UIView, which contains UITextView with some text. This is how to change UITextView background color:
self.view.opaque = YES;
self.view.backgroundColor = [UIColor yellowColor];
self.textView.opaque = NO;
self.textView.backgroundColor = [UIColor clearColor];
self.textView.textColor = [UIColor orangeColor];
Not what I was looking for, but might as well write down, looks useful enough. Another tool in the toolbox, even though everything still looks like a nail.


  1. Thanks! I could not figure out why Xcode was showing my background color to my chosen one but when I ran it on the device/simulator it was still white!

    Edit: I see what I was doing wrong when setting the value... I had set it in Xcode, but still had bad code in the controller for the view. Instead of using 0.0 to 1.0 as values, I was using 8-bit color codes (250, 145, 10) for my values! Doh!

  2. can u change the default color of link in UITextView

  3. As far as I know, you can NOT change link color in UITextView. If it's really important, you could use UIWebView and some CSS.