I do not understand how to remove a shadow that was added to a view. I add to my view in initWithFrame
a shadow in this way:
self.layer.borderWidth = 2; self.layer.borderColor = [UIColor clearColor].CGColor; self.backgroundColor = [UIColor greenColor]; [self.layer setCornerRadius:8.0f]; CALayer *layer = self.layer; layer.shadowOffset = CGSizeMake(2, 2); layer.shadowColor = [[UIColor blackColor] CGColor]; layer.cornerRadius = 8.0f; layer.shadowRadius = 3.0f; layer.shadowOpacity = 0.80f; layer.shadowPath = [[UIBezierPath bezierPathWithRect:layer.bounds] CGPath];
After in the execution of the app I want to remove the shadow from this view. I've tried using:
layer.hidden = YES;
or
self.layer.hidden = YES;
but this hides the view completely, not just the added shadow.
Is there a way to retrieve the added shadow from a view and then hide it? Thanks!
shadowColor sets the color of the shadow, and needs to be a CGColor . shadowOpacity sets how transparent the shadow is, where 0 is invisible and 1 is as strong as possible. shadowOffset sets how far away from the view the shadow should be, to give a 3D offset effect. shadowRadius sets how wide the shadow should be.
The layer's shadow uses several elements: shadowOffset , shadowColor , shadowOpacity , and shadowRadius . Each element changes the respective appearance. You can offset the shadow differently to change the direction the shadow is cast - how far from the layer and in which direction.
I guess you could use the shadowOpacity
property of your CALayer
.
So this should work:
self.layer.shadowOpacity = 0;
See the CALayer
's shadowOpacity
documentation page
And to show your shadow use:
self.layer.shadowOpacity = 1.0;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With