Problem with layer.shadowColor and UIColors

Trying to change the color of the shadow. It works:

self.layer.shadowColor = [[UIColor blueColor] CGColor]; 

enter image description here

but I want to make it a normal color, so I tried:

 self.layer.shadowColor = [[UIColor colorWithRed:191/255.0f green:199/255.0f blue:203/255.0f alpha:1] CGColor]; 

enter image description here

which does not work.

what am I doing wrong?

EDIT:

code snippet from my init method:

 self.layer.shadowOpacity = 0; self.layer.shadowColor = [[UIColor blueColor] CGColor]; //self.layer.shadowColor = [[UIColor colorWithRed:191/255.0f green:199/255.0f blue:203/255.0f alpha:1] CGColor]; self.layer.shadowOffset = CGSizeMake(0,0); self.layer.shadowRadius = 4; 

EDIT 2:

The odd part is that I extended UIColor to include some of my custom colors; if i use:

 self.layer.shadowColor = [[UIColor pointColorBlue] CGColor]; 

from my UIColor + myColor:

 +(UIColor *) pointColorBlue { return [UIColor colorWithRed:50/255.0f green:50/255.0f blue:255/255.0f alpha:1]; } 

It works great.

0
source share
2 answers

Bah! figured it out: the graphic guy gave me that RGB value, which is almost identical to the background color!

+1
source

Those should work.

But you should do the following:

 CALayer newLayer = [CALayer layer]; newLayer.shadowColor = [[UIColor blueColor] CGColor]; self.layer = newLayer; [self.layer setWantsLayer:YES]; 

It is important to reset the main layer, otherwise it will not be drawn.

0
source

Source: https://habr.com/ru/post/954638/


All Articles