SwiftUI Previews Light/Dark Mode
SwiftUI Previews Light/Dark Mode
Preview your UI in both light and dark modes to ensure contrast and readability.
Preview light and dark modes
Set a preferred color scheme in previews to spot contrast issues and verify colors in both modes.
Example
import SwiftUI
struct DemoView: View { var body: some View { Text("Hello") } }
#Preview("Light") {
DemoView()
.preferredColorScheme(.light)
}
#Preview("Dark") {
DemoView()
.preferredColorScheme(.dark)
}
In the example above, the .preferredColorScheme(.dark) modifier is used to set the preferred color scheme to dark.