So I set the shadow of a layer of an UIView correctly the first time (it shows perfectly fine) but when I try to change the color (nothing else, just the layer.shadowColor
) it won't update in the view. It still shows the original color. I already tried layer setNeedsDisplay
without any luck.
self.profileIconShadow.layer.cornerRadius = self.profileIcon.frame.size.height / 2;
self.profileIconShadow.layer.shadowColor = [UIColor blackColor].CGColor;
self.profileIconShadow.layer.shadowOpacity = 1.0f;
self.profileIconShadow.layer.shadowRadius = self.profileIcon.frame.size.width * .025;
self.profileIconShadow.layer.shadowOffset = CGSizeZero;
// if ([entry[@"isInactive"] boolValue]) { // Original
if (true) { // Overrode temporarily to test it out
self.profileIconShadow.layer.shadowColor = [UIColor redColor].CGColor;
[self.profileIconShadow.layer setNeedsDisplay];
}
The shadow get set correctly the first time as needed. But then I try changing the color it still stays black instead of turning red.
This is how it should look.
Edit #2: I have noticed that if I comment out the black color when I first make the shadow, it will change to red later on. Can I not change shadowColor
multiple times?
I tried your code last night, i even made an animation of on and off switch out of your code before i went to sleep.. haha..
The question:
Can I not change shadowColor multiple times?
, of course you can.. ;)The only potential reason why your layer is not updating is maybe it is not executed in the main thread, to make sure try this: