IOS: create a UIImage or UIImageView with rounded corners

cyclingIsBetter picture cyclingIsBetter · Oct 9, 2011 · Viewed 90.7k times · Source

Is it possible create an UIImage or an UIImageView with rounded corners? Because I want take an UIImage and show it inside an UIImageView, but I don't know how to do it.

Answer

yinkou picture yinkou · Oct 9, 2011

Yes, it is possible.
Import the QuartzCore (#import <QuartzCore/QuartzCore.h>) header and play with the layer property of the UIImageView.

yourImageView.layer.cornerRadius = yourRadius;
yourImageView.clipsToBounds = YES;

See the CALayer class reference for more info.