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!
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!
If you are using iOS 3+, you can do the following:
myTextView.clipsToBounds = YES;
myTextView.layer.cornerRadius = 10.0f;
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;
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
}
}
}
myTextView.layer.cornerRadius = 20
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.
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.