- (void)viewDidLoad
{
[super viewDidLoad];
UIView *view=[[UIView alloc]initWithFrame:CGRectMake(110,150, 100,100)];
view.backgroundColor=[UIColorredColor];//设置背景颜色
view.layer.cornerRadius=50;//设置圆的半径;根据view的宽度和高度而定。要求view的宽度=高度;半径=宽度(高度)/2
[self.viewaddSubview:view];
[view release];
}
显示效果如下:
如果只想让圆的边界有颜色,园内没有颜色,那么可以设置如下:
- (void)viewDidLoad
{
[super viewDidLoad];
UIView *view=[[UIView alloc]initWithFrame:CGRectMake(110, 150, 100, 100)];
view.backgroundColor=[UIColor clearColor];
//边界是1像素的红线
view.layer.borderWidth=0.5;
view.layer.borderColor=[UIColor redColor].CGColor;
view.layer.cornerRadius= 50;
[self.view addSubview:view];
[view release];
}
显示如下: