Monday, February 3, 2014

Rounded Corners on UIView

UIView has a number of API's to perform simple customization. To perform more sophisticated customizations on UIView, it's required to drop down into the view's CALayer which is accessed via the layer property. The cornerRadius property of CALayer can be set to perform corner rounding.

UIView *roundedView = [[UIView alloc] initWithFrame:CGRectMake(50,50,100,100)];  
 [roundedView setBackgroundColor:[UIColor redColor]];  
 roundedView.layer.cornerRadius = 10.0f;  
 [self.view addSubview:roundedView];  

Each of the four corners is rounded and a higher value for cornerRadius will perform a higher degree of rounding.

 roundedView.layer.cornerRadius = 30.0f;