# DatePicker

{% hint style="info" %}
<mark style="color:red;">**struct**</mark> **DatePicker**\<Label> where Label : [`View`](https://developer.apple.com/documentation/swiftui/view)
{% endhint %}

{% tabs %}
{% tab title="💾 程式" %}
:point\_right: SwiftUI Tutorials ⟩ Working with UI Controls ⟩ Sec 3. [Define the Profile Editor](https://developer.apple.com/tutorials/swiftui/working-with-ui-controls#Define-the-Profile-Editor)

```swift
var dateRange: ClosedRange<Date> {
    let min = Calendar.current.date(byAdding: .year, value: -1, to: profile.goalDate)!
    let max = Calendar.current.date(byAdding: .year, value: 1, to: profile.goalDate)!
    return min...max
}

DatePicker(
    selection: $profile.goalDate,
    in: dateRange,
    displayedComponents: .date
) {
    Text("Goal Date").bold()
}
```
{% endtab %}

{% tab title="📘 手冊" %}
* [SwiftUI](https://developer.apple.com/documentation/swiftui) ⟩ [Views and Controls](https://developer.apple.com/documentation/swiftui/views-and-controls)
  * [DatePicker](https://developer.apple.com/documentation/swiftui/datepicker)
{% endtab %}

{% tab title="📗 參考" %}
* [ ] [Getting UIKit's UICalendarView from iOS 16 fully functioning in a SwiftUI app](http://chriswu.com/posts/swiftui/uicalendarview/)
{% endtab %}

{% tab title="👥 相關" %}
* [date](../../../swift/scope/framework/built-in-frameworks/foundation/date "mention")
* [calendar](../../../swift/scope/framework/built-in-frameworks/foundation/calendar "mention")
{% endtab %}
{% endtabs %}
