Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UIView shadow not working

This is my code.

listView.layer.masksToBounds = NO; listView.layer.shadowOffset = CGSizeMake(-3, 3); listView.layer.shadowColor=[[UIColor blackColor] CGColor]; listView.layer.shadowRadius = 4; listView.layer.shadowOpacity = 1.0; [listView.layer setShouldRasterize:YES]; 

It works good with shadow effect.

While changing

listView.layer.masksToBounds = YES; 

I didnt get shadow effect.

like image 749
Anbu Raj Avatar asked Apr 30 '12 13:04

Anbu Raj


2 Answers

The shadow is actually drawn below the UIView. If you set maskToBounds to YES, this clips any drawing outside of the UIView frame. Here is a SO link that describes this in more detail.

like image 118
bbarnhart Avatar answered Sep 23 '22 04:09

bbarnhart


The shadow is drawn outside of the layer's bounds. You have to set listView.layer.masksToBounds = NO to see the shadow

if you set listView.layer.masksToBounds = YES you can't draw anything out side of bounds so you can not get shadow

like image 45
Hector Avatar answered Sep 24 '22 04:09

Hector