1. Add UIView and set backgroundColor = nil
2. The rounded
private func settingRoundCorner(a) {
let roundLayer = CAShapeLayer()
roundLayer.fillColor = UIColor.red.cgColor
let rect = roundView.bounds
roundLayer.frame = rect
let roundPath = UIBezierPath(roundedRect: rect, cornerRadius: 20)
roundLayer.path = roundPath.cgPath
// Mask can also be used to create rounded corners, but cannot be used to create shadows
// roundView.layer.mask = roundLayer
roundView.layer.addSublayer(roundLayer)
}
Copy the code
3. The shadow
private func settingShadow(a) {
let rect = roundView.bounds
roundView.layer.shadowColor = UIColor.black.cgColor
roundView.layer.shadowRadius = 20
roundView.layer.shadowOpacity = 0.69
// Setting shadowOffset produces an off-screen render
// roundView.layer.shadowOffset = CGSize(width: 5, height: 5)
let path = UIBezierPath(rect: rect.offsetBy(dx: 5, dy: 5))
roundView.layer.shadowPath = path.cgPath
}
Copy the code
The Demo address