UIButton *button = [[UIButton alloc]initWithFrame:CGRectMake(0, 0, 200, 60)];
button.center = self.view.center;
button.backgroundColor = [UIColor blueColor];
[button setTitle:@"世界那么大" forState:UIControlStateNormal];
[button setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
[button addTarget:self action:@selector(clickBtn:) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:button];
CGRect rect = button.bounds;
//所切圆角尺寸
CGSize radio = CGSizeMake(30, 30);
//可以自己设置所切的圆角
UIRectCorner corner = UIRectCornerTopLeft|UIRectCornerTopRight|UIRectCornerBottomLeft;
UIBezierPath *path = [UIBezierPath bezierPathWithRoundedRect:rect byRoundingCorners:corner cornerRadii:radio];
CAShapeLayer *masklayer = [[CAShapeLayer alloc]init];
masklayer.frame = button.bounds;
masklayer.path = path.CGPath;
button.layer.mask = masklayer;
网友评论