Thursday, April 15, 2010

UITextView with border

Yes, you can have your  UITextView with a border and that too with a rounded corner. I was in search of a way to achieve this for over 6 months and could not get it. So did a work around for that, by drawing a view  with lines around and behind the UITextView.

But today I stumbled upon this thread and was able to discover a way to do that.

Any way I will share the code here. If there are any negative implications behind this solution, please share it.

Code:


yourTextView.layer.borderWidth = 1;
yourTextView.layer.cornerRadius = 8; //This is for achieving the rounded corner.
yourTextView.layer.borderColor = [[UIColor grayColor] CGColor];


And don't forget to include the Quartz core framework. 

#import <QuartzCore/QuartzCore.h>

Bye !

1 comment:

  1. Brilliant. This has been bugging me for longer than I care to think. So simple too.

    Just need to add the internal shadow somehow.

    Many thanks for posting

    ReplyDelete