Border around UITextView
Asked Answered
E

4

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?

Energumen answered 6/7, 2011 at 20:4 Comment(0)
L
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
Logistics answered 28/12, 2011 at 10:38 Comment(2)
Anyway to set back to the default?Worden
@Worden just try changing the values of border width and corner radius.Logistics
P
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

Persuasion answered 13/1, 2015 at 9:15 Comment(0)
P
2

Solution :

contentView.layer.borderWidth = 2.0f;
contentView.layer.borderColor = [[UIColor blueColor] CGColor];
contentView.layer.cornerRadius = 5;
Pastorship answered 4/11, 2016 at 11:46 Comment(0)
G
0

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

How to style UITextview to like Rounded Rect text field?

Gulgee answered 18/8, 2011 at 15:29 Comment(1)
This is no way to post an answer, the link can be broken anytime.Edinburgh

© 2022 - 2024 — McMap. All rights reserved.