Programmatically detect dark mode in SwiftUI to display appropriate Image

后端 未结 2 2157
余生分开走
余生分开走 2021-02-19 05:14

In Assets.xcassets, there is an ability to add additional images that will automatically switch based on the Appearances. This works well for static images but I\'m

2条回答
  •  孤独总比滥情好
    2021-02-19 05:59

    There's an @Environment variable.

    @Environment (\.colorScheme) var colorScheme:ColorScheme
    

    Here's how I use it to fill an empty Rectangle:

    Rectangle().fill(Color.fillColor(for: colorScheme))
    

提交回复
热议问题