Reputation: 13
I'm trying to add a shadow under my custom view, I have the following code:
CGContextSaveGState(context);
CGContextSetShadow(context, CGSizeMake(0, 2), 3.0);
CGRect shadowRect = CGRectMake(self.bounds.origin.x,
self.bounds.origin.y + self.bounds.size.height,
self.bounds.size.width,
3.0);
CGContextFillRect(context, shadowRect);
CGContextRestoreGState(context);
But the shadow isn't visible.
Upvotes: 1
Views: 661
Reputation: 7343
Try this:
UIColor *color = [UIColor grayColor];
CGColorRef gray = color.CGColor;
self.layer.shadowColor = gray;
self.layer.shadowOffset = CGSizeMake(0, 0);
self.layer.shadowRadius = 2;
self.layer.shadowOpacity = 1;
self.layer.borderColor = red;
self.layer.shadowPath = [UIBezierPath bezierPathWithRect:self.bounds].CGPath;
self.layer.masksToBounds = NO;
Upvotes: 2