1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
let btn = UIButton()
btn.frame = CGRect(x: 100, y: 300, width: 100, height: 40)
btn.layer.cornerRadius = 20
btn.layer.masksToBounds = true
btn.backgroundColor = UIColor.red
        
let shadowView = UIView()
shadowView.layer.shadowColor = UIColor.gray.cgColor
shadowView.layer.shadowOffset = CGSize(width: 0, height: 2)
shadowView.layer.shadowRadius = 6
shadowView.layer.shadowOpacity = 0.5   
shadowView.frame = btn.frame
shadowView.layer.cornerRadius = 20
shadowView.layer.shadowPath = UIBezierPath(roundedRect: btn.bounds.insetBy(dx: 5, dy: 0), cornerRadius: btn.layer.cornerRadius).cgPath
        
self.view.addSubview(shadowView)
self.view.addSubview(btn)