问题
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 ?
回答1:
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.
回答2:
#import <QuartzCore/QuartzCore.h>
and link against QuartzCore
回答3:
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.
来源:https://stackoverflow.com/questions/8669553/round-corners-uiview-or-uiimageview