33

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!

Jakub
  • 3,129
  • 8
  • 44
  • 63
  • Possible duplicate of [How to round the corners of a button](https://stackoverflow.com/questions/5047818/how-to-round-the-corners-of-a-button) – georgeawg Jul 25 '18 at 16:02

6 Answers6

91

If you are using iOS 3+, you can do the following:

myTextView.clipsToBounds = YES;
myTextView.layer.cornerRadius = 10.0f;
bstahlhood
  • 2,006
  • 13
  • 10
  • 1
    Just let other Xamarin users know, you can use this code, and don't need to worry about QuartzCore. (fyi, I'm on Xamarin iOS 8.10.3.2, targetting iOS 8.4) – terry Jul 16 '15 at 06:40
11

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;
Suresh Varma
  • 9,750
  • 1
  • 60
  • 91
7

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
        }
    }
}
Antzi
  • 12,831
  • 7
  • 48
  • 74
5

Swift 4.2

myTextView.layer.cornerRadius = 20
Sentry.co
  • 5,355
  • 43
  • 38
  • IMO Its the modern answer to an old problem. As there was no swift answer already here, i simply provided it. I belive more people will come here looking for the swift answer than the obj-c answer as this tops google search if you search for `UITextView rounded corner swift` – Sentry.co Jul 25 '18 at 18:46
5

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.

herock
  • 69
  • 1
  • 2
-1

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:

DCKit: rounded button

It also has many other cool features, such as text fields with validation, controls with borders, dashed borders, circle and hairline views etc.

Andrey Gordeev
  • 30,606
  • 13
  • 135
  • 162