Border around UITextView

Jack picture Jack · Jul 6, 2011 · Viewed 39.1k times · Source

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?

Answer

Krishna Shanbhag picture Krishna Shanbhag · Dec 28, 2011
 #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