1 CALayer *layer = [[self.view.layer sublayers] objectAtIndex:0]; layer.shadowPath = (layer.shadowPath) ? nil : [self bezierPathWithCurvedShadowForRect:layer.bounds2 ].CGPath;
1 static const CGFloat offset = 10.0; 2 static const CGFloat curve = 5.0; 3 - (UIBezierPath*)bezierPathWithCurvedShadowForRect:(CGRect)rect { 4 5 UIBezierPath *path = [UIBezierPath bezierPath]; 6 7 CGPoint topLeft = rect.origin; 8 CGPoint bottomLeft = CGPointMake(0.0, CGRectGetHeight(rect) + offset); 9 CGPoint bottomMiddle = CGPointMake(CGRectGetWidth(rect)/2, CGRectGetHeight(rect) - curve); 10 CGPoint bottomRight = CGPointMake(CGRectGetWidth(rect), CGRectGetHeight(rect) + offset);11 CGPoint topRight = CGPointMake(CGRectGetWidth(rect), 0.0);12 13 [path moveToPoint:topLeft]; 14 [path addLineToPoint:bottomLeft];15 [path addQuadCurveToPoint:bottomRight controlPoint:bottomMiddle];16 [path addLineToPoint:topRight];17 [path addLineToPoint:topLeft];18 [path closePath];19 20 return path;21 }