Reputation: 4037
how to set rounded corner for a UITextView ?
Upvotes: 8
Views: 9432
Reputation: 2477
Work for me as below code and step
create textView var
@IBOutlet weak var currentAddressOutlet: KMPlaceholderTextView!
create this function
private func setBorderForTextView() {
self.currentAddressOutlet.layer.borderColor = UIColor.lightGray.cgColor
self.currentAddressOutlet.layer.borderWidth = 0.5
self.currentAddressOutlet.layer.cornerRadius = 5
}
call above function in your viewDidLoad
override func viewDidLoad() {
super.viewDidLoad()
setupTable()
setBorderForTextView()
}
Result is here
Upvotes: 0
Reputation: 38654
I define an category class for UITextView in .h:
@interface UITextView (RoundedCorner)
-(void) roundedCornerDefault;
-(void) roundedCornerWithRadius:(CGFloat) radius
borderColor:(CGColorRef) color
borderWidth:(CGFloat) width;
@end
and the implementation class:
#import <QuartzCore/QuartzCore.h>
#import "UITextView+RoundedCorner.h"
@implementation UITextView (RoundedCorner)
-(void) roundedCornerDefault {
[self roundedCornerWithRadius:10
borderColor:[[UIColor grayColor] CGColor]
borderWidth:1];
}
-(void) roundedCornerWithRadius:(CGFloat) radius
borderColor:(CGColorRef) color
borderWidth:(CGFloat) width {
self.layer.cornerRadius = radius;
self.layer.borderColor = color;
self.layer.borderWidth = width;
self.clipsToBounds = YES;
}
@end
Example to use it:
#import "UITextView+RoundedCorner.h"
...
[self.myTextView roundedCornerDefault];
Upvotes: 1
Reputation: 2241
fist import the file
#import <QuartzCore/QuartzCore.h>
and then set the property of your text view
yourTextViewName.layer.cornerRadius = kCornerRadius;
where kCornerRadius
is a constant you set as a radius for corner
Upvotes: 20
Reputation: 9740
Try this it will work for sure
you have to import
QuartzCore/QuartzCore.h
UITextView* txtView = [[UITextView alloc] initWithFrame:CGRectMake(50, 50, 300, 100)];
txtView.layer.cornerRadius = 5.0;
txtView.clipsToBounds = YES;
Upvotes: 5