我试图绕一个按钮的两个角落。这是我正在使用的代码。
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
我不明白为什么这不起作用。有人可以向我解释一下吗?
答案 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)];