Reputation: 3129
in many iPhone apps I could see UITextView with rounded corners. Is there a simple way to achieve this? or do I need to create a custom UITextView? any links to examples showing how to achieve this?
Thanks!
Upvotes: 33
Views: 24272
Reputation: 13444
Just a quick reminder: you can do it easily from the the stroyboard/xib:
Or create an extension, and set it programmatically or through the storyboard
extension UIView {
@IBInspectable var cornerRadius: CGFloat {
set {
layer.cornerRadius = newValue
layer.masksToBounds = newValue > 0
}
get {
return layer.cornerRadius
}
}
}
Upvotes: 7
Reputation: 32469
You may want to check out my library called DCKit. It's written on the latest version of Swift.
You'd be able to make a rounded corner text view/button/text field from the Interface builder directly:
It also has many other cool features, such as text fields with validation, controls with borders, dashed borders, circle and hairline views etc.
Upvotes: -1
Reputation: 9740
Add QuartzCore framework to the app and then
#import <QuartzCore/QuartzCore.h>
UITextView* txtView = [[UITextView alloc] initWithFrame:CGRectMake(50, 50, 300, 100)];
txtView.layer.cornerRadius = 5.0;
txtView.clipsToBounds = YES;
Upvotes: 11
Reputation: 69
The easiest way I have found is to put the Rounded Rect button with no text under the UITextView, take the UITextView smaller than button.
Done.
Upvotes: 5
Reputation: 2006
If you are using iOS 3+, you can do the following:
myTextView.clipsToBounds = YES;
myTextView.layer.cornerRadius = 10.0f;
Upvotes: 91