简体   繁体   中英

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.

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM