UIBezierPath:byRoundingCorners:不起作用

时间:2015-08-10 12:02:46

标签: ios uibezierpath rounded-corners

我试图绕一个按钮的两个角落。这是我正在使用的代码。

let bezierSelectAllPath = UIBezierPath(roundedRect: selectAllButton.bounds, byRoundingCorners: UIRectCorner.BottomRight.union(UIRectCorner.TopRight), cornerRadii: CGSizeMake(4.0, 4.0))

        let maskSelectLayer = CAShapeLayer()
        maskSelectLayer.frame = selectAllButton.bounds
        maskSelectLayer.path = bezierSelectAllPath.CGPath
        selectAllButton.layer.mask = maskSelectLayer

我不明白为什么这不起作用。有人可以向我解释一下吗?

1 个答案:

答案 0 :(得分:0)

最后这样做

[selectAllButton.layer addSublayer:maskSelectLayer];

而不是

selectAllButton.layer.mask = maskSelectLayer

您可以像这样设置按钮的角落:

UIBezierPath * bezierSelectAllPath = [UIBezierPath bezierPathWithRoundedRect:button.bounds
                                            byRoundingCorners:UIRectCornerTopLeft | UIRectCornerTopRight
                                                  cornerRadii:CGSizeMake(4.0, 4.0)];