개요
아이폰을 쓰다보면 여러개중에 하나를 선택하는 뷰를 본적이 있을 것이다.
그런 것을 구현할 때쓰는 피커를 알아보고 다양한 종류의 피커를 알아보겠다.
Picker
struct Picker<Label, SelectionValue, Content> where Label : View, SelectionValue : Hashable, Content : View
selection에는 바인딩된 프로퍼티랑 피커가 보여줄 콘텐츠들이 필요하다.
임시로 할 테스트 할 때는 selection에 .constant로 고정값을 넣어줄 수 있다.
iOS에서 피커는 5가지가 있다.
- DefaultPickerStyle
- InlinePickerStyle
- MenuPickerStyle
- WheelPickerStyle
- SegmentedPickerStyle
1 |
|
DefaultPickerStyle
.pickerStyle(.automatic)
로 선언하거나 안적으면 된다.
![](https://user-images.githubusercontent.com/79088896/182816284-4d16cd45-1305-4ee6-93bb-a581efc6b0e1.png)
inlinePickerStyle
.pickerStyle(.inline)
로 선언하면된다.
![](https://user-images.githubusercontent.com/79088896/182816597-525e1415-8b95-430a-8d8a-ce42ff067f88.png)
menuPickerStyle
.pickerStyle(.menu)
로 선언하면된다.
![](https://user-images.githubusercontent.com/79088896/182816918-ab133de8-7a3c-4dca-84c7-33fefa623568.png)
wheelPickerStyle
.pickerStyle(.wheel)
로 선언하면된다.
![](https://user-images.githubusercontent.com/79088896/182817223-be362c0b-afc9-4391-b29a-d4748f602861.png)
segmentedPickerStyle
.pickerStyle(.segmented)
로 선언하면된다.
![](https://user-images.githubusercontent.com/79088896/182817505-dad6ec62-c4ed-4729-b641-3cd25a30d51a.png)
DatePicker
날짜 피커.
종류로는 4가지가 있다.
- DefaultDatePickerStyle
- WheelDatePickerStyle
- GraphicalDatePickerStyle
- CompactDatePickerStyle (default랑 같게 나온다. 뭐지?)
1 |
|
DefaultPickerStyle
선언안하거나 .datePickerStyle(.automatic)
으로 선언하면된다.
![](https://user-images.githubusercontent.com/79088896/182817941-d9d90032-f1bf-43f3-a99f-a9acd9478c91.png)
WheelPickerStyle
선언안하거나 .datePickerStyle(.wheel)
으로 선언하면된다.
![](https://user-images.githubusercontent.com/79088896/182819366-8fed2fd6-e1eb-4b15-93f8-9a694bc202c5.png)
GraphicalDatePickerStyle
선언안하거나 .datePickerStyle(.graphical)
으로 선언하면된다.
![](https://user-images.githubusercontent.com/79088896/182819639-dd013075-f674-42e3-a27c-151d23dc3ad1.png)
ColorPicker
1 |
|
![](https://user-images.githubusercontent.com/79088896/182860229-67451293-6515-4b52-9240-5adc72ee43d3.png)