What are the label colors of these disabled SwiftUI buttons? I would like to use the colors in my own button styles so that they are consistent with the existing styles.
I found that they have some transparency. Also, they are different in light and dark mode. But none of the system colors seems to match. I experimented with transparency, too, without success so far.
import SwiftUI
struct ButtonTestView: View {
var body: some View {
VStack(alignment: .leading) {
Button("Button", action: {})
.disabled(true)
Button("Button (same BG as bordered)", action: {})
.disabled(true)
.background(Color(.secondarySystemFill))
Button("BorderedButton", action: {})
.buttonStyle(.bordered)
.disabled(true)
// Same with different background
VStack(alignment: .leading) {
Button("Button", action: {})
.disabled(true)
Button("Button (same BG as bordered)", action: {})
.disabled(true)
.background(Color(.secondarySystemFill))
Button("BorderedButton", action: {})
.buttonStyle(.bordered)
.disabled(true)
}.background(Color(.label))
Spacer()
}.padding()
}
}
Light mode:
Dark mode:
Personally, I use.opacity(isDisable? 0.5: 1) on my button or stack to present disabled buttons. It will give you the disabled effect look and the transparent look too.
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.