I want to set Custom buttonStyle
modifier for button for light and dark mode.
How to change buttonStyle Modifier based on light or dark mode? I want to set Cus
Just put that condition inside button style modifier, like
// ... other your code
})
.buttonStyle(CustomButtonStyle(scheme: colorScheme)) // << here !!
and in custom style
struct CustomButtonStyle: ButtonStyle {
var scheme: ColorScheme // << here !!
func makeBody(configuration: Self.Configuration) -> some View {
configuration.label
.padding(10)
Group {
if configuration.isPressed {
Circle() // example of internal dependency on scheme
.fill(self.scheme == .dark ? Color.offBlack : Color.offWhite)
// .. other code here
}
You could define a named color in Assets.xcassets with a variation for the dark mode:
This works out of the box even in a ButtonStyle:
Color("ButtonBorder")