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?
Asked
Active
Viewed 4.0k times
4 Answers
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
-
Anyway to set back to the default? – lostintranslation Jan 06 '16 at 21:31
-
@lostintranslation just try changing the values of border width and corner radius. – Krishna Shanbhag Jan 07 '16 at 08:11
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:
-
This is no way to post an answer, the link can be broken anytime. – Ümañg ßürmån Nov 22 '18 at 12:34