> For the complete documentation index, see [llms.txt](https://lochiwei.gitbook.io/ios/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://lochiwei.gitbook.io/ios/swiftui/control/pickers/datepicker.md).

# 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](/ios/swift/scope/framework/built-in-frameworks/foundation/date.md)
* [Calendar](/ios/swift/scope/framework/built-in-frameworks/foundation/calendar.md)
  {% endtab %}
  {% endtabs %}
