Jakub
Jakub

Reputation: 3129

UITextView with rounded corners

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

Answers (6)

Antzi
Antzi

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

Sentry.co
Sentry.co

Reputation: 5569

Swift 4.2 🔸

myTextView.layer.cornerRadius = 20

Upvotes: 6

Andrey Gordeev
Andrey Gordeev

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:

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.

Upvotes: -1

Suresh Varma
Suresh Varma

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

herock
herock

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

bstahlhood
bstahlhood

Reputation: 2006

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

myTextView.clipsToBounds = YES;
myTextView.layer.cornerRadius = 10.0f;

Upvotes: 91

Related Questions