Created
September 13, 2021 15:42
-
-
Save kkebo/6206fd02d7b4c76890a85943d089630b to your computer and use it in GitHub Desktop.
iOS の Light/Dark mode 選択の設定みたいな Picker
This file contains 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 PlaygroundSupport | |
import SwiftUI | |
struct ContentView: View { | |
@State var selection = 0 | |
var body: some View { | |
HStack { | |
Button { | |
self.selection = 0 | |
} label: { | |
VStack(spacing: 10) { | |
Color.white | |
.frame(maxWidth: .infinity, maxHeight: .infinity) | |
Text("hoge") | |
if self.selection == 0 { | |
Image(systemName: "checkmark.circle.fill") | |
.imageScale(.large) | |
.foregroundColor(.blue) | |
} else { | |
Image(systemName: "circle") | |
.imageScale(.large) | |
.foregroundColor(.secondary) | |
} | |
} | |
.foregroundColor(.primary) | |
} | |
Button { | |
self.selection = 1 | |
} label: { | |
VStack(spacing: 10) { | |
Color.white | |
.frame(maxWidth: .infinity, maxHeight: .infinity) | |
Text("fuga") | |
if self.selection == 1 { | |
Image(systemName: "checkmark.circle.fill") | |
.imageScale(.large) | |
.foregroundColor(.blue) | |
} else { | |
Image(systemName: "circle") | |
.imageScale(.large) | |
.foregroundColor(.secondary) | |
} | |
} | |
.foregroundColor(.primary) | |
} | |
} | |
} | |
} | |
PlaygroundPage.current.setLiveView(ContentView()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment