4
@IBOutlet weak var selectorSemiView: UIView!
@IBOutlet weak var blurEffect: UIVisualEffectView!
@IBOutlet var outerAreaRecognizer: UITapGestureRecognizer!
override func viewDidLoad() {
    super.viewDidLoad()
    selectorSemiView.layer.cornerRadius = 15
    selectorSemiView.layer.shadowColor = UIColor.gray.cgColor
    selectorSemiView.layer.shadowOffset = CGSize.zero
    selectorSemiView.layer.shadowRadius = 7

}

selectorSemiView is a container view

When I run this app, there is no shadow and no rounded corner.

What's wrong in my code?

Junwoo Lee
  • 489
  • 1
  • 5
  • 15

2 Answers2

10

your code is fine but you forget to set the opacity, if you need the more information you can get the another answer in SO, for e.g

 selectorSemiView.layer.cornerRadius = 15
    selectorSemiView.layer.shadowColor = UIColor.gray.cgColor
    selectorSemiView.layer.shadowOffset = CGSize.zero  
    selectorSemiView.layer.shadowOpacity = 1.0
    selectorSemiView.layer.shadowRadius = 7.0
    selectorSemiView.layer.masksToBounds =  false

output

enter image description here

Community
  • 1
  • 1
Anbu.Karthik
  • 82,064
  • 23
  • 174
  • 143
  • 3
    When I include selectorSemiView.clipsToBounds = true, There is rounded corner but no shadow, but when I don't include selectorSemiView.clipsToBounds = true , there is shadow but now rounded corner – Junwoo Lee Apr 23 '17 at 04:40
  • 2
    Thats because shadow is applied **outside** the bounds and `clipsToBounds` well clips out. You need to fake this behaviour by adding another view of the same size and adding shadow on to it. – Rikh Apr 23 '17 at 08:54
  • why clip to bounds is not working when apply shadow by using this solution ? With my height constant when i am setting it to 0, inner content still displays. – Mitesh Dobareeya May 23 '20 at 07:28
1

you need to add

selectorSemiView.clipsToBounds = true
dRAGONAIR
  • 1,181
  • 6
  • 8