简体   繁体   中英

UIBezierPath: byRoundingCorners: doesn't work

I'm trying to round just 2 corners of a button. This is the code I am using.

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

I don't understand why this doesn't work. Can someone explain this to me?

Do this at the end

[selectAllButton.layer addSublayer:maskSelectLayer];

instead of

selectAllButton.layer.mask = maskSelectLayer

and you can set your button's corners like this :

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM