Swift 设置部分圆角 功能

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

使用扩展为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
    }
   }

使用方法:

UIView.setRoundCorners(corners: [UIRectCorner.topLeft,UIRectCorner.topRight], with: 10)

猜你喜欢

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