【Swift5】ボタンなどのViewに影を落とす。
UIViewのエクステンションとして実装しました。
extension UIView {
func dropShadow(){
self.layer.cornerRadius = 15
self.layer.shadowColor = UIColor.black.cgColor
self.layer.shadowOffset = CGSize(width: 4, height: 4)
self.layer.shadowOpacity = 0.4
self.layer.shadowRadius = 4
}
}
対象のビューに.dropShadow()を実行します。