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
?
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.
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.
UIImage contains the data for an image. UIImageView is a custom view meant to display the UIImage . Save this answer.
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With