UIView任意位置裁剪圆角
extension UIView {
/// 裁剪 view 的圆角
func clipRectCorner(direction: UIRectCorner, cornerRadius: CGFloat) {
let cornerSize = CGSize(width: cornerRadius, height: cornerRadius)
let maskPath = UIBezierPath(roundedRect: bounds, byRoundingCorners: direction, cornerRadii: cornerSize)
let maskLayer = CAShapeLayer()
maskLayer.frame = bounds
maskLayer.path = maskPath.cgPath
layer.addSublayer(maskLayer)
layer.mask = maskLayer
}
}
例:
view.clipRectCorner(direction: [.topLeft,.topRight], cornerRadius: 10.0)
网友评论