swift 设置view的部分圆角

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/qq_30963589/article/details/83145544

设置圆角 给UIView添加一个扩展:

extension UIView {
    //设置部分圆角
    func setRoundCorners(corners:UIRectCorner,with radii:CGFloat){
        let bezierpath:UIBezierPath = UIBezierPath.init(roundedRect: self.bounds, byRoundingCorners: corners, cornerRadii: CGSize(width: radii, height: radii))
        let shape:CAShapeLayer = CAShapeLayer.init()
        shape.path = bezierpath.cgPath
        
        self.layer.mask = shape
    }
}

//调用:
controlView.setRoundCorners(corners: [UIRectCorner.topLeft, UIRectCorner.topRight], with: 5)

猜你喜欢

转载自blog.csdn.net/qq_30963589/article/details/83145544