//
//  SWBezierCorner.swift
//  SWComment
//
//  Created by Alan on 2019/10/9.
//  Copyright © 2019 liuhongli. All rights reserved.
//

import UIKit

class SWBezierCorner: NSObject {
    static let shared = SWBezierCorner()
    
    /// 上方的左右圆角
    ///
    /// - Parameters:
    ///   - view: 需要`削圆角`的view
    ///   - topLeft: 左上
    ///   - topRight: 右上
    ///   - topLeftRadius: 左上圆角半径
    ///   - topRightRadius: 右上圆角半径
    func cornerPath(_ view: UIView,
                    _ topLeft: UIRectCorner,
                    _ topRight: UIRectCorner,
                    _ cornerRadius: CGFloat) {
        let path = UIBezierPath.init(roundedRect: view.bounds, byRoundingCorners: [topLeft, topRight], cornerRadii: CGSize(width: cornerRadius, height: 0))
        let maskLayer = CAShapeLayer.init()
        maskLayer.frame = view.bounds
        maskLayer.path = path.cgPath
        view.layer.mask = maskLayer
    }
    
    /// 四个圆角(左上,右上,左下,右下)
    func cornerPath(_ view: UIView,
                    _ topLeft: UIRectCorner,
                    _ topRight: UIRectCorner,
                    _ bottomLeft: UIRectCorner,
                    _ bottomRight: UIRectCorner,
                    _ cornerRadius: CGFloat) {
        let path = UIBezierPath.init(roundedRect: view.bounds, byRoundingCorners: [topLeft, topRight, bottomLeft, bottomRight], cornerRadii: CGSize(width: cornerRadius, height: 0))
        let maskLayer = CAShapeLayer.init()
        maskLayer.frame = view.bounds
        maskLayer.path = path.cgPath
        view.layer.mask = maskLayer
    }
}
