圆形的UIView或者UIButton

//先定义一个UIView

UIView * view = [[UIView alloc] initWithFrame:CGRectMake(50, 50, 50, 50)];

//圆的半径是view宽的一半

view.layer.cornerRadius = view.frame.size.width / 2;

//是否进行剪切

view.clipsToBounds = YES;

//  给view一个颜色

view.backgroundColor = [UIColor redColor];

//添加到视图上

[self.View addSubview:view];

//UIButton

UIButton * = [UIButton buttonWithType:(UIButtonTypeRoundedRect)];

button.frame =CGRectMake(10, 10, 50, 50);

button.layer.cornerRadius = button.frame.size.width /2;

button.clipsToBounds = YES;

[self.view addSubview:button];

你可能感兴趣的:(圆形的UIView或者UIButton)