dyllandry
dyllandry

Reputation: 113

Adding Shadows to UIViews

I have been scouring on and off for a few days now how to properly add a drop shadow to a UIView. There are many resources on the topic, but none so far have worked for me. The shadow does not appear.

 cell.buttonView.layer.shadowColor = UIColor.blackColor().CGColor
 cell.buttonView.layer.shadowOffset = CGSizeMake(4, 4)
 cell.buttonView.layer.shadowRadius = 5
 cell.buttonView.layer.shadowOpacity = 1.0
 cell.buttonView.layer.masksToBounds = false

Altering masksToBounds was because the absence of that step in another person's code seemed to be the reason as to why they could not get their shadow to appear.

Upvotes: 2

Views: 1125

Answers (1)

Fantattitude
Fantattitude

Reputation: 1842

Your code is good (and works, just tried it). The problem must be somewhere else.

Note that the shadow will only apply if your view has content. So if your view's backgroundColor is clearColor it won't display the shadow.

Also check your code is running and not runned only in some cases ;)

Upvotes: 1

Related Questions