1
所以我第一次正確地設置了一個UIView圖層的陰影(它顯示完全正常),但是當我嘗試更改顏色時(沒有別的,只是layer.shadowColor
)它不會更新風景。它仍然顯示原始的顏色。我已經試過layer setNeedsDisplay
沒有任何運氣。CALayer shadowColor not changing
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'某處SE? – 0yeoj
@ 0yeoj我只有代碼,我先將它設置爲黑色,然後再變爲紅色。 – Victor