Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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 ?

like image 845
Illep Avatar asked Dec 29 '11 15:12

Illep


People also ask

How do I round corners in UIImageView?

Make UIImageView Corners RoundedSetting the corner radius to 100 will make the image view completely rounded. Try different corner radius like 10, 20, 30, 40 to get image corners of different radius. To make the image border and visible I will set the borderWidth and the borderColor.

How do you round UIView corners?

If you start with a regular UIView it has square corners. You can give it round corners by changing the cornerRadius property of the view's layer . and smaller values give less rounded corners. Both clipsToBounds and masksToBounds are equivalent.

What is the difference between UIImage and UIImageView?

UIImage contains the data for an image. UIImageView is a custom view meant to display the UIImage . Save this answer.

What is use of UIImageView?

The class provides controls to set the duration and frequency when animating multiple images. It also allows you to stop and start the animation. All images associated with a UIImageView object should use the same scale.


1 Answers

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.

like image 100
Guillaume Avatar answered Oct 04 '22 10:10

Guillaume