Skip to content

Instantly share code, notes, and snippets.

@kkebo
Created September 13, 2021 15:42
Show Gist options
  • Save kkebo/6206fd02d7b4c76890a85943d089630b to your computer and use it in GitHub Desktop.
Save kkebo/6206fd02d7b4c76890a85943d089630b to your computer and use it in GitHub Desktop.
iOS の Light/Dark mode 選択の設定みたいな Picker
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