The issue is just with your shadowPath
.
Using CGRectMake(frame.origin.x, frame.size.height, frame.size.width, 15)
to create your UIBezierPath
will set an incorrect origin.
First, origin.x
should be 0.0f
or the shadow will shift far away if your UIView
's origin.x != 0.0f
. Second, you need to line up the bottom of the shadowPath
with the bottom of your UIView
.
This is a screenshot of UIView
s using your shadow code illustrating these issues. (In the lower UIView
you cannot see the shadow because it is far off the right of the screen).
You will see what you intended if you change the rect to:
const CGFloat shadowRectHeight = 15.0f;
CGRect shadowRect = CGRectMake(0.0f, self.bounds.size.height - shadowRectHeight, self.bounds.size.width, shadowRectHeight)];