swift cornerRadius只有左下角和左下角右上?

时间:2016-06-27 16:37:33

标签: swift

快速转角半径问题

let path = UIBezierPath(roundedRect:username.bounds, byRoundingCorners:[.TopRight, .BottomLeft], cornerRadii: CGSizeMake(20, 20))
        let maskLayer = CAShapeLayer()
        maskLayer.path = path.CGPath
        username.layer.mask = maskLayer

Output

I Want

1 个答案:

答案 0 :(得分:0)

如果您将视图子类化为您想要提供的角落,则可以这样做:

override func layoutSubviews() {
        super.layoutSubviews()

        maskLayer.frame = self.bounds
        maskLayer.path = UIBezierPath(roundedRect: bounds, byRoundingCorners: UIRectCorner.topLeft.union(.topRight), cornerRadii: CGSize(width: 25, height: 25)).cgPath
        self.layer.mask = maskLayer
    }