To create rounded rectangular views using iPhone SDK

To create view with rounded corners is really simple in iPhone SDK 3.0 in just 2 steps

Step 1: Include QuartzCore


Step 2: You can now add corner radius to any view

UIImageView * imageView = [[UIImageView alloc] initWithFrame:CGRectMake(10, 100, 300, 225)];

[imageView setImage:[UIImage imageNamed:@"candle.jpg"]];

[imageView.layer setMasksToBounds:YES];

[imageView.layer setCornerRadius:10.0];

[imageView.layer setBorderColor:[[UIColor whiteColor] CGColor]];

[imageView.layer setBorderWidth:3.0];

[self.view addSubview:imageView];
[imageView release];

Sample Code: Click to download. In the sample I have done a image view and a loading view with rounded corners. This sample will work only with iPhone SDK 3.0 and above.

If you had got the chance to look at iPhone SDK 3.2 beta you will be surprised to see more exciting stuff that is been added to CALayer 😀

By Imthiaz

Programmer, SAAS, CMS & CRM framework designer, Love Linux & Apple products, Currently addicted to mobile development & working @bluebeetle