//
// ContentView.swift
// picker_swift_tutorial
//
// Created by devdepot on 2021/04/28.
//
import SwiftUI
enum colorIndex{
case red,green,blue
}
struct ContentView: View {
func getColorByValue(value:Int) -> String{
switch value {
case 0:
return "레드"
case 1:
return "그린"
case 2:
return "블루"
default:
return "레드"
}
}
@State private var selectionValue = 0
// var colorIdx: colorIndex
var body: some View {
VStack(alignment: .center){
Circle()
.foregroundColor(/*@START_MENU_TOKEN@*/.blue/*@END_MENU_TOKEN@*/)
.frame(width: 50, height: 50)
Text("세그먼트 value : \(selectionValue)")
Text("선택된 색깔 : \(self.getColorByValue(value: selectionValue))")
Picker(
"피커"
,selection: $selectionValue
,content:{
Text("레드").tag(0)
Text("그린").tag(1)
Text("블루").tag(2)
}
).pickerStyle(SegmentedPickerStyle())
.cornerRadius(10)
.padding(.horizontal,10)
Picker(
"피커"
,selection: $selectionValue
,content:{
Text("레드").tag(0)
Text("그린").tag(1)
Text("블루").tag(2)
}
)
.frame(width: 70, height: /*@START_MENU_TOKEN@*/100/*@END_MENU_TOKEN@*/)
.clipped()
.border(Color.blue, width: 10)
}
}
}
struct ContentView_Previews: PreviewProvider {
static var previews: some View {
ContentView()
}
}