All the solutions from this thread did not work for me when the application was in production. It only works during the development process.
More over, I am not sure that adding the UIView.appearance(whenContainedInInstancesOf:) call within the @main app entry initializer is a good practice as swiftUI views call it every time the view redraws.
The trick for me was calling appearance without the parameter whenContainedInInstancesOf of appearance(), on a onAppear() modifier.
It also work only when setting the color this way: UIColor(named: "AccentColor"). Calling UIColor(.accentColor)from SwiftUIColor` does not work.
@main
struct AwesomeApp: App {
var body: some Scene {
WindowGroup {
Group {
ContentView()
}
.onAppear { UIView.appearance().tintColor = UIColor(named: "AccentColor") }
}
}
}
Post
Replies
Boosts
Views
Activity
It seems that on my side, the startAccessingSecurityScopedResource() method throws an error and can not access the user Privacy settings. When looking in the iPhone Settings -> Privacy -> Files and Folders, my application doesn't appear and it seems that it has no access to this part of iOS. Have you been able to solve your question since?
I have found a way to set the system background color using SwiftUI. It is pretty handy when you want the background color in dark mode of the modal view..foregroundColor(Color(UIColor.systemBackground))
Have you tried any setup in your application scheme settings under Test? You must change it to add the .xctestplan file.