CAShapeLayer cutout in UIView
问题 My goal is to create a pretty opaque background with a clear rounded rect inset let shape = CGRect(x: 0, y: 0, width: 200, height: 200) let maskLayer = CAShapeLayer() maskLayer.path = UIBezierPath(roundedRect: shape, cornerRadius: 16).cgPath maskLayer.fillColor = UIColor.clear.cgColor maskLayer.fillRule = kCAFillRuleEvenOdd let background = UIView() background.backgroundColor = UIColor.black.withAlphaComponent(0.8) view.addSubview(background) constrain(background) { $0.edges == $0.superview!