swiftUI moon shape

I would like to create moon shape. currently, I archived it by placing another circle on top and then giving it the same colour as the background colour. I was wondering if there's a better way to do this? perhaps using a clipped shape or masking layer.

ZStack{

Circle().foregroundColor(isDarkMode ? Color( colorLiteral(red: 0.8039215803, green: 0.8039215803, blue: 0.8039215803, alpha: 1)) : Color.yellow)

.frame(width: 30, height: 30)

.offset(x: isDarkMode ? 20 : -20)

Circle().foregroundColor(isDarkMode ? Color( colorLiteral(red: 0.1764705926, green: 0.4980392158, blue: 0.7568627596, alpha: 1)) : Color.white)

.frame(width: 30, height: 30)

.offset(x: isDarkMode ? 6 : -20).rotationEffect(.degrees( isDarkMode ? -40 : 0))

}


Read more here: https://stackoverflow.com/questions/64402650/swiftui-moon-shape

Content Attribution

This content was originally published by test testing at Recent Questions - Stack Overflow, and is syndicated here via their RSS feed. You can read the original post over there.

%d bloggers like this: