Illep
Illep

Reputation: 16849

Round corners UIView or UIImageView

I need to add Round corners to a UIImageView. I found a solution from a forum, and i tried the following code;

UIImageView * roundedView = [[UIImageView alloc] initWithImage: [UIImage imageNamed:@"wood.jpg"]];
// Get the Layer of any view
CALayer * l = [roundedView layer];
[l setMasksToBounds:YES];
[l setCornerRadius:10.0];

I am using iOS 5, and setMasksToBounds:YES and setCornerRadius are not found.

So is there any other way i could get round corners in my UIImageview ?

Upvotes: 8

Views: 4461

Answers (3)

MusiGenesis
MusiGenesis

Reputation: 75386

Add this line to your .h file:

#import <QuartzCore/QuartzCore.h>

... and the warnings will go away (the code will still work without the import). Your problem has nothing to do with iOS 5.

Upvotes: 1

Guillaume
Guillaume

Reputation: 21736

To make rounded corners on a UIView (or its subclass UIImageView), you need, like you wrote in your question, to set the cornerRadius on your layer. For example:

theRoundedCornersView.layer.cornerRadius = 10.0f;

Import the right header and it will compile:

#import <QuartzCore/QuartzCore.h>

Don't forget to link against it by adding it to your frameworks.

Upvotes: 14

Chakalaka
Chakalaka

Reputation: 2827

#import <QuartzCore/QuartzCore.h>

and link against QuartzCore

Upvotes: 4

Related Questions