How do I mask a square image to have round corners in the iPhone SDK?

Here’s a quick and easy way to create images with rounded corners.

UIImageView * headerImage = [[UIImageView alloc] initWithFrame:CGRectMake(10.0, 10.0, 64.0, 64.0)];
headerImage.image = contactPhoto;

CALayer * layer = [headerImage layer];
[layer setMasksToBounds:YES];
[layer setCornerRadius:10.0];

[layer setBorderWidth:1.0];
[layer setBorderColor:[[UIColor blackColor] CGColor]];

[contactHeader addSubview:headerImage];

Leave a Reply

Your email address will not be published.