SwiftUI - How do I check to see if dark mode is enabled?

后端 未结 4 527
太阳男子
太阳男子 2020-12-22 05:36

How do I check to see if dark mode on the device is enabled. I want to check this from within a view and conditionally show or hide a shadow.

I thought I could jus g

4条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-12-22 06:03

    Thanks to @dfd for pointing out that I can't use an if statement with a modifier. I updated my code like this for now. This just returns different versions of the circle in light and dark mode.

    if colorScheme == .light {
        Circle()
            .foregroundColor(Color(RetroTheme.shared.appMainTint))
            .frame(width: 50, height: 50, alignment: .center)
            .shadow(color: .secondary, radius: 5, x: 0, y: 0)
    } else {
        Circle()
            .foregroundColor(Color(RetroTheme.shared.appMainTint))
            .frame(width: 50, height: 50, alignment: .center)
    }
    

提交回复
热议问题