Problem
In some cases, SwiftUI’s Alert
and ActionSheet
buttons don’t use accent color by default unless users tap & move their finger on them. This is weird and buggy.
Attempt
It’s attempting to add the following constructor to the struct with @main
attribute:
|
But without specifying the containerTypes
parameter in UIView.appearance()
, it will affect other views as well. For example, the foreground color of swipe actions in List
will also be changed to the accent color, which is not what we want.
Docs: appearance(whenContainedInInstancesOf:)
Solution
Be more specific about the container types:
|
Notice that by specifying the container types as above, the foreground color navigation items will be set to the default blue.
Add .tint(.accentColor)
will fix this:
|
You may also want to define tint color for swipeActions buttons (a simple .tint(_:)
will work).