title: How do I change button backgroundcolor if the button is disabled in swiftUI
body: <p>I'm trying to create a buttonStyle that has a different background color if the button is disabled.</p>
  <p>How do I do that?
  I've created the code below to react to a variable that I've introduced myself, but is it possible to have it react on the buttons .disabled() state?</p>
  <p>My code:</p>
  <pre><code>struct MyButtonStyle: ButtonStyle {
      var enabledState = false
  
      func makeBody(configuration: Self.Configuration) -&gt; some View {
          configuration.label
              .foregroundColor(Color.white)
              .padding(10)
              .padding(.horizontal, 20)
              .background(self.enabledState ? Color(UIColor.orange) : Color(UIColor.lightGray))
              .cornerRadius(20)
              .frame(minWidth: 112, idealWidth: 112, maxWidth: .infinity, minHeight: 40, idealHeight: 40, maxHeight: 40, alignment: .center)
              .scaleEffect(configuration.isPressed ? 0.9 : 1.0)
      }
  }
  
  struct ContentView: View {
      @State private var buttonEnabled = false
  
      var body: some View {
          HStack {
              Button(&quot;Button&quot;) {
                  self.buttonEnabled.toggle()
                  print(&quot;Button pressed&quot;)
              }
          }
          .buttonStyle(MyButtonStyle(enabledState: self.buttonEnabled))
      }
  }
  
  struct ContentView_Previews: PreviewProvider {
      static var previews: some View {
          ContentView()
      }
  }
  </code></pre>