Created
April 3, 2021 08:16
-
-
Save monsoir/8b5f8016b989e17b06d18f23c7c648ff to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// use in a custom view | |
override func layoutSubviews() { | |
super.layoutSubviews() | |
setupShadow() | |
} | |
private var shadowLayer: CAShapeLayer! // layer for shadow back | |
private func setupShadow() { | |
guard columnStackView.bounds.size != .zero else { return } | |
if shadowLayer == nil { | |
shadowLayer = CAShapeLayer() | |
shadowLayer.path = UIBezierPath(roundedRect: <target view>.frame, cornerRadius: <shadow corner radius>).cgPath | |
shadowLayer.fillColor = <shadow color>.cgColor | |
shadowLayer.shadowColor = <shadow color>.cgColor | |
shadowLayer.shadowPath = shadowLayer.path | |
// width for x offset according to <target view>'s frame | |
// height for y offset according to <target view>'s frame | |
shadowLayer.shadowOffset = CGSize(width: 0, height: 15) | |
shadowLayer.shadowOpacity = 1 | |
shadowLayer.shadowRadius = 8 | |
} | |
layer.insertSublayer(shadowLayer, at: 0) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment