設置按鈕的4個角:
左上:UIRectCornerTopLeft
左下:UIRectCornerBottomLeft
右上:UIRectCornerTopRight
右下:UIRectCornerBottomRight
例子代碼:
UIButton *button = [[UIButton alloc] initWithFrame:CGRectMake(50, 60, 80, 40)];
button.backgroundColor = [UIColor orangeColor];
[self.view addSubview:button];
//這裡設置的是左上和左下角
UIBezierPath *maskPath = [UIBezierPath bezierPathWithRoundedRect:button.bounds byRoundingCorners:UIRectCornerBottomLeft | UIRectCornerTopLeft cornerRadii:CGSizeMake(8, 8)];
CAShapeLayer *maskLayer = [[CAShapeLayer alloc] init];
maskLayer.frame = button.bounds;
maskLayer.path = maskPath.CGPath;
button.layer.mask = maskLayer;
效果圖: