//
//  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()
    }
}

'IOS > SwiftUI' 카테고리의 다른 글

(오류)Attempt to set a non-property-list object  (0) 2021.05.12
(SwiftUI)16.lazyGridView  (0) 2021.04.29
(SwiftUI)14.토스트,팝업  (0) 2021.04.28
(SwiftUI)13.TextField  (0) 2021.04.28
(SwiftUI)12.커스톰 탭뷰  (0) 2021.04.28

+ Recent posts