Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SwiftUI: Force View to use light or dark mode [duplicate]

Is it possible in SwiftUI to force a View to use light or dark mode — like overrideUserInterfaceStyle in UIKit does?

like image 812
ixany Avatar asked Sep 04 '25 16:09

ixany


1 Answers

.colorScheme() is deprecated does not work with the background well.

.preferredColorScheme() is the way now. Does the job with the background too.

TestView1()
   .preferredColorScheme(.dark)

TestView2()
   .preferredColorScheme(.light)

Developer docs for .preferredColorScheme()

like image 161
Jorge Frias Avatar answered Sep 07 '25 16:09

Jorge Frias