Created
April 2, 2020 08:26
-
-
Save dymx101/c640da95e0f5400168cbd5674056aabc to your computer and use it in GitHub Desktop.
A container view helps drop shadow
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
class ShadowContainer: UIView { | |
init(child: UIView, | |
shadowRadius: CGFloat = 2, | |
shadowOffset: CGSize = CGSize.zero, | |
shadowOpacity: Float = 0.3) { | |
super.init(frame: CGRect.zero) | |
translatesAutoresizingMaskIntoConstraints = false | |
addSubview(child) | |
child.leadingAnchor.constraint(equalTo: leadingAnchor).isActive = true | |
child.trailingAnchor.constraint(equalTo: trailingAnchor).isActive = true | |
child.topAnchor.constraint(equalTo: topAnchor).isActive = true | |
child.bottomAnchor.constraint(equalTo: bottomAnchor).isActive = true | |
layer.shadowRadius = shadowRadius | |
layer.shadowOffset = shadowOffset | |
layer.shadowOpacity = shadowOpacity | |
layer.cornerRadius = child.layer.cornerRadius | |
} | |
required init?(coder: NSCoder) { | |
fatalError("init(coder:) has not been implemented") | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment