Add shadow and rounded corners to a UIView
WHAT IT TESTS: CALayer shadow and corner properties plus the masksToBounds conflict. OUTLINE: cornerRadius needs masksToBounds true, but that clips the shadow; set shadowPath to keep both and stay performant.
WHAT IT TESTS: Whether you know the layer properties and the classic clipping-versus-shadow conflict. ANSWER OUTLINE: Rounded corners come from layer.cornerRadius, which usually requires masksToBounds or clipsToBounds true to clip content. Shadows come from shadowColor, shadowOffset, shadowRadius, shadowOpacity. The problem: clipping for the corner also clips the shadow, so they fight. The fix is to set an explicit shadowPath, which lets the shadow render outside while content stays rounded, and avoids the off-screen pass.
Read the original → interview
- #ios
- #uikit
- #calayer
- #shadow
- #performance
Get five bites like this every day.
Tezvyn delivers a daily feed of 60-second tech bites with quizzes to lock in what you learn.