32

How do you add a border around a UITextView (like a UITextField)? I want to allow users to type multiple lines, but unfortunately a UITextField does not support this. Is there an easy way to do this in code or do I need to create one in Photoshop?

Jack
  • 361
  • 1
  • 4
  • 6

4 Answers4

74
 #import <QuartzCore/QuartzCore.h> 

Import the above framework and include these lines in your class where textview is defined.

[[self.textview layer] setBorderColor:[[UIColor grayColor] CGColor]];
[[self.textview layer] setBorderWidth:2.3];
[[self.textview layer] setCornerRadius:15];

Swift solution.

self.textview.layer.borderColor = UIColor.gray.cgColor              
self.textview.layer.borderWidth = 2.3                
self.textview.layer.cornerRadius = 15
Krishna Shanbhag
  • 1,519
  • 13
  • 33
25

Swift solution:

    var textView = UITextView(frame: CGRectMake(0,0,100,100))
    textView.layer.cornerRadius = 5
    textView.layer.borderColor = UIColor.purpleColor().CGColor
    textView.layer.borderWidth = 1

No need to import QuarzCore in iOS8

Esqarrouth
  • 38,543
  • 21
  • 161
  • 168
2

Solution :

contentView.layer.borderWidth = 2.0f;
contentView.layer.borderColor = [[UIColor blueColor] CGColor];
contentView.layer.cornerRadius = 5;
Deepak Kumar
  • 1,035
  • 10
  • 18
0

If you do a quick search, you'll find several answers. Example:

How to style UITextview to like Rounded Rect text field?

Community
  • 1
  • 1
Reinhold
  • 234
  • 2
  • 10