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?
Border around UITextView
Asked Answered
#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
Anyway to set back to the default? –
Worden
@Worden just try changing the values of border width and corner radius. –
Logistics
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
Solution :
contentView.layer.borderWidth = 2.0f;
contentView.layer.borderColor = [[UIColor blueColor] CGColor];
contentView.layer.cornerRadius = 5;
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. –
Edinburgh
© 2022 - 2024 — McMap. All rights reserved.