【发布时间】:2015-06-20 17:25:47
【问题描述】:
所以我第一次正确设置了 UIView 图层的阴影(它显示得非常好)但是当我尝试更改颜色时(没有别的,只是 layer.shadowColor)它不会在视图中更新.它仍然显示原始颜色。我已经尝试过layer setNeedsDisplay,但没有任何运气。
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];
}
根据需要第一次正确设置阴影。但后来我尝试改变颜色,它仍然保持黑色而不是变成红色。
这就是它应该的样子。
编辑#2:我注意到如果我在第一次制作阴影时将黑色注释掉,稍后它会变为红色。我可以不多次更改shadowColor吗?
【问题讨论】:
-
试过了,对我来说效果很好。你确定你没有在其他地方给
self.profileIconShadow.layer.shadowColor分配颜色吗? -
@0yeoj 我只有一开始将其设置为黑色然后应更改为红色的代码。
标签: ios objective-c calayer shadow