设置圆角 给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)