Skip to content

Instantly share code, notes, and snippets.

@oocoocococo
Created July 27, 2020 10:15
Show Gist options
  • Save oocoocococo/e42264144416ae947d496067333f9306 to your computer and use it in GitHub Desktop.
Save oocoocococo/e42264144416ae947d496067333f9306 to your computer and use it in GitHub Desktop.
struct ContentView: View {
/// タブの種類
enum Tab {
case circle
case triangle
}
/// 選択中のタブ
@State private var selection: Tab = .circle
var body: some View {
TabView(selection: $selection) {
Text("丸のビュー")
.tabItem {
Image(systemName: selection == .circle ?
"circle.fill" : // 選択時
"circle") // 非選択時
.imageScale(.large)
Text("丸")
}
.tag(Tab.circle) // タブの種類を指定
Text("三角のビュー")
.tabItem {
Image(systemName: selection == .triangle ?
"triangle.fill" : // 選択時
"triangle") // 非選択時
.imageScale(.large)
Text("三角")
}
.tag(Tab.triangle) // タブの種類を指定
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment