G. Marc
G. Marc

Reputation: 5997

Smartest way to set color for enabled/disabled buttons with SwiftUI

I'd like to set the color of a Text view inside a Button view based on whether the button is enabled or disabled. What is the smartest way to do this and also to get the system default colors for enabled/disabled colors, because I don't want to set any gray shade, I'd like to set the "normal" gray shade.

Upvotes: 4

Views: 3400

Answers (2)

Heyman
Heyman

Reputation: 539

Here is how to do it in SwiftUI 2.0

Button("PressME", action: {self.playerAttemptCount += 1
                           }).buttonStyle(PlainButtonStyle())

This way, the button automatically gets a gray color if it is disabled.

Upvotes: 1

G. Marc
G. Marc

Reputation: 5997

Actually, adding .buttonStyle(.plain) to the button just did what I was looking for. Now, the button automatically gets a gray color if it's disabled.

Upvotes: 9

Related Questions