Top of the page
Close

This is a red error

This is a red error

This is a red error

UIView programmatically with rounded corners

Ondrej Rafaj on 2010.04.15 22:09:49

Short snippet that explains how to create new UIView programmatically, and than setu rounded corners, background color and than add this view to your main view on the screen

// don't forget to import quartz core
#import <QuartzCore/QuartzCore.h>

// setting up size and position of the UIView
int leftBorder = 20;
int topBorder = 35;
int width = 150;
int height = 160;

// creating new view
UIView *myView = [[UIView alloc] initWithFrame:CGRectMake(leftBorder, topBorder, width, height)];

// setting up rounded corners
myView.layer.cornerRadius = 10;

// setting color for our view
myView.backgroundColor = [UIColor redColor];

// adding our new view on the
[self.view addSubview:myView];

Be aware that this functionality works with iPhone SDK 3.0 and newer, and you have to have the QuartzCore framework imported in your project :)

Ondrej Rafaj

Ondrej Rafaj

Independent iPhone developer @ ondrej-rafaj.co.uk

I am available to give you a free quote or start working on your project ... just give me a call or drop a line. Please find all my details on my portfolio site ondrej-rafaj.co.uk

Back to top Comment

Comments ... Why not to get involved!

We had to disable comments till the problem with spam will be solved, sorry for any inconvenience caused.

Back to top

IE SUCKS, DON'T USE IT :) Digg this page