UITextView with rounded corners
in many iPhone apps I could see UITextView with rounded corners. Is there a simple way to ach开发者_如何学Pythonieve 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
}
}
}
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.
精彩评论