Created
October 23, 2024 16:24
-
-
Save takoikatakotako/e5e398182be03e6b9e38143dc4aa8dd3 to your computer and use it in GitHub Desktop.
SwiftUIでButtonを有効にしたり無効にしたりする
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import SwiftUI | |
| struct ContentView: View { | |
| @State var enable: Bool = true | |
| var body: some View { | |
| VStack { | |
| Toggle(isOn: $enable) { | |
| Text("isEnable: \(enable.description)") | |
| } | |
| Button { | |
| print("Tapped!!") | |
| } label: { | |
| Text("Tap Me!!(\(enable ? "Enable": "Disable"))") | |
| .foregroundColor(Color.white) | |
| .padding() | |
| .background(enable ? Color.orange: Color(UIColor.lightGray)) | |
| } | |
| .disabled(!enable) | |
| }.padding() | |
| } | |
| } | |
| #Preview { | |
| ContentView() | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment