Trouble with layer.shadowColor and UIColors

拟墨画扇 提交于 2019-12-13 21:21:23

问题


Trying to change the color of a shadow. This works:

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

but i want to make it a custom color, so i tried:

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

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:

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 fine.


回答1:


Bah! figured it out: the graphics guy gave me that RGB value which is nearly identical to the background color!




回答2:


Those should work.

But you have to do following:

CALayer newLayer = [CALayer layer];
newLayer.shadowColor = [[UIColor blueColor] CGColor];

self.layer = newLayer;
[self.layer setWantsLayer:YES];

It's important to reset the main layer, cause otherways it does not get drawn.



来源:https://stackoverflow.com/questions/12358851/trouble-with-layer-shadowcolor-and-uicolors

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!