Created
June 8, 2019 08:38
-
-
Save kutan74/529e3d6946978a7b72fe28fbdd889dbf to your computer and use it in GitHub Desktop.
SwiftUI Segment Control Example
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
// | |
// ContentView.swift | |
// Pop | |
// | |
// Created by KUTAN ÇINGISIZ on 6.06.2019. | |
// Copyright © 2019 KUTAN ÇINGISIZ. All rights reserved. | |
// | |
import SwiftUI | |
struct ContentView : View { | |
// Selected segment Index | |
@State var segmentIndex = 0 | |
var colors = ["Red", "Green", "Blue"] | |
var subColors = [ | |
["Red 1", "Red 2", "Red 3"], | |
["Green 1", "Green 2", "Green 3"], | |
["Blue 1", "Blue 2", "Blue 3"] | |
] | |
var body: some View { | |
VStack { | |
SegmentedControl(selection: $segmentIndex) { | |
ForEach(0..<colors.count) { index in | |
Text(self.colors[index]) | |
} | |
}.padding() | |
List(subColors[segmentIndex].identified(by: \.self)) { item in | |
Text(item) | |
} | |
Spacer() | |
} | |
} | |
} | |
#if DEBUG | |
struct ContentView_Previews : PreviewProvider { | |
static var previews: some View { | |
ContentView() | |
} | |
} | |
#endif | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment