Declaration
Initializers
8 SwiftUI initializers back <MultiDatePicker>. The props you pass pick one.
<MultiDatePicker
selection: Binding<{ era?: number; year?: number; month?: number; day?: number; hour?: number; minute?: number; second?: number; }[]>
>
children?: ReactNode
</MultiDatePicker>nonisolated init(
selection: Binding<Set<DateComponents>>,
@ContentBuilder label: () -> Label
)selection*Binding<{ era?: number; year?: number; month?: number; day?: number; hour?: number; minute?: number; second?: number; }[]>The date values being displayed and selected.
childrenReactNodeContent. Strings become
Text; React Native views are laid out by Yoga and placed by SwiftUI.Swift
label: () -> Label
Also takes the common view props: modifiers, style and testID.
Overview
Use a MultiDatePicker when you want to provide a view that allows the
user to select multiple dates.
The following example creates a basic MultiDatePicker, which appears as a
calendar view representing the selected dates:
@State private var dates: Set<DateComponents> = []
var body: some View {
MultiDatePicker("Dates Available", selection: $dates)
}You can limit the MultiDatePicker to specific ranges of dates
allowing selections only before or after a certain date or between two
dates. The following example shows a multi-date picker that only permits
selections within the 6th and (excluding) the 16th of December 2021
(in the UTC time zone):
@Environment(\.calendar) var calendar
@Environment(\.timeZone) var timeZone
var bounds: Range<Date> {
let start = calendar.date(from: DateComponents(
timeZone: timeZone, year: 2022, month: 6, day: 6))!
let end = calendar.date(from: DateComponents(
timeZone: timeZone, year: 2022, month: 6, day: 16))!
return start ..< end
}
@State private var dates: Set<DateComponents> = []
var body: some View {
MultiDatePicker("Dates Available", selection: $dates, in: bounds)
}You can also specify an alternative locale, calendar and time zone through
environment values. This can be useful when using a PreviewProvider to
see how your multi-date picker behaves in environments that differ from
your own.
The following example shows a multi-date picker with a custom locale, calendar and time zone:
struct ContentView_Previews: PreviewProvider {
static var previews: some View {
MultiDatePicker("Dates Available", selection: .constant([]))
.environment(\.locale, Locale.init(identifier: "zh"))
.environment(
\.calendar, Calendar.init(identifier: .chinese))
.environment(\.timeZone, TimeZone(abbreviation: "HKT")!)
}
}From Apple’s SwiftUI documentation. Code samples there are Swift.
Relationships
Conforms to
- View
See also
More in Controls.
- ButtonA control that initiates an action.
- ColorPickerA control used to select a color from the system color picker UI.
- DatePickerA control for selecting an absolute date.
- DisclosureGroupA view that shows or hides another content view, based on the state of a disclosure control.
- OutlineGroupA structure that computes views and disclosure groups on demand from an underlying collection of tree-structured, identified data.
- PasteButtonA system button that reads items from the pasteboard and delivers it to a closure.
- PickerA control for selecting from a set of mutually exclusive values.
- SecureFieldA control into which people securely enter private text.
- SliderA control for selecting a value from a bounded linear range of values.
- StepperA control that performs increment and decrement actions.
- SubscriptionViewA view that subscribes to a publisher with an action.
- TableA container that presents rows of data arranged in one or more columns, optionally providing the ability to select one or more members.