Archive for January 13th, 2010

Snippet: Round Corners

Here’s a clever snippet for displaying an image with rounded corners by masking it at runtime:

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];

Mucking around with the view’s CALayer hadn’t occurred to us before, but if this does look half-decent, we’ve got some compositing code that’s in line for tossing. As they say, the only guaranteed bugfree code is the code you don’t write…

h/t: iPhoneFlow!

Continue Reading →
0