Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UIView shadow, cornerradius not working

Tags:

ios

swift

uiview

@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?

like image 510
Junwoo Lee Avatar asked Jan 04 '23 03:01

Junwoo Lee


1 Answers

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

like image 94
Anbu.Karthik Avatar answered Jan 22 '23 19:01

Anbu.Karthik