圆形UIView

UIButton * button = [UIButton buttonWithType:UIButtonTypeRoundedRect];

button.frame = CGRectMake(20.f40.f120.f120.f);

button.layer.cornerRadius = 60;

button.layer.masksToBounds = YES;

button.layer.borderWidth = 1.0;

button.layer.borderColor = [UIColor blueColor].CGColor;

[button setTitle:@"圆按钮" forState:UIControlStateNormal];

[self.view addSubview:button];

想要实现圆形,需要将layer的cornerRadius(角半径)的大小设置为button宽高的一半。

当然,你一定要将button的width和height设置为等值。

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