Swift - How to apply the drop shadow only on UIButton Bottom Shadow but not for its image and its title label?

3749 views ios

I'm trying to add drop shadow to UIButton but I want to have only the shadow for UIButton bottom shadow only not for its image and title. I followed UIButton bottom shadow but it didn't work. Basically, here is what I'm having right now: enter image description here

And here is what I want to have: enter image description here

This is my current code:

button.layer.borderWidth = 0.5
button.layer.borderColor = UIColor.gray.cgColor
button.layer.shadowColor = UIColor.black.cgColor
button.layer.shadowOffset = CGSize(width: 0, height: 2)
button.layer.shadowOpacity = 1.0
button.layer.shadowRadius = 0
button.layer.masksToBounds = false

Please help. Thanks in advance.

answered question

It looks like your button has transparent background, changing it's background to the white should do the trick.

1 Answer


Hi dear best way to apply shadow for transparent button you just need to embed your button in view and apply shadow effect on that view.

posted this

Have an answer?


Please login first before posting an answer.