let label = UILabel(frame: CGRect(x: 50, y: 100, width: 100, height: 50))
label.backgroundColor = UIColor.orange
label.textColor = UIColor.white
label.text = "圆角设置"
label.textAlignment = .center
label.layer.mask = self.configRectCorner(view: label, corner: [topLeft, .topRight, bottomLeft, .bottomRight], radii: CGSize(width: 15, height: 15))
self.view.addSubview(label)
/// 圆角设置
///
/// - Parameters:
/// - view: 需要设置的控件
/// - corner: 哪些圆角
/// - radii: 圆角半径
/// - Returns: layer图层
func configRectCorner(view: UIView, corner: UIRectCorner, radii: CGSize) -> CALayer {
let maskPath = UIBezierPath.init(roundedRect: view.bounds, byRoundingCorners: corner, cornerRadii: radii)
let maskLayer = CAShapeLayer.init()
maskLayer.frame = view.bounds
maskLayer.path = maskPath.cgPath
return maskLayer
}
网友评论