DateTimePicker
public struct DateTimePicker
extension DateTimePicker: View
extension DateTimePicker: _ViewEmptyChecking
DateTimePicker provides a title and value label with Fiori styling and a DatePicker.
Usage
@State var customizedDate: Date = .init(timeIntervalSince1970: 0.0)
@State var isRequired = false
@State var showsErrorMessage = false
@State var customizedPickerVisible = false
let customizedDateFormatter: DateFormatter = {
let formatter = DateFormatter()
formatter.dateFormat = "MM/dd/yyyy HH:mm:ss"
return formatter
}()
func mandatoryFieldIndicator() -> TextOrIcon {
var indicator = AttributedString("*")
indicator.font = .fiori(forTextStyle: .title3)
indicator.foregroundColor = Color.preferredColor(.indigo7)
return .text(indicator)
}
@State var customizedPickerVisible = false
DateTimePicker(title: "Customized Date Formatter, locale and calendar", mandatoryFieldIndicator: self.mandatoryFieldIndicator(), isRequired: self.isRequired, selectedDate: self.$customizedDate, dateFormatter: self.customizedDateFormatter, pickerVisible: self.$customizedPickerVisible)
.environment(\.locale, Locale(identifier: "zh-Hans"))
.environment(\.calendar, Calendar(identifier: .gregorian))
-
init(title:valueLabel: controlState: errorMessage: range: selectedDate: dateFormatter: pickerComponents: dateStyle: timeStyle: noDateSelectedString: pickerVisible: hidesSeparator: showsClearAction: clearAction: componentIdentifier: ) Undocumented
Declaration
Swift
public init(@ViewBuilder title: () -> any View, @ViewBuilder valueLabel: () -> any View = { EmptyView() }, controlState: ControlState = .normal, errorMessage: AttributedString? = nil, range: ClosedRange<Date>? = nil, selectedDate: Binding<Date?> = .constant(nil), dateFormatter: DateFormatter? = nil, pickerComponents: DatePicker.Components = [.date, .hourAndMinute], dateStyle: Date.FormatStyle.DateStyle = .abbreviated, timeStyle: Date.FormatStyle.TimeStyle = .shortened, noDateSelectedString: String? = nil, pickerVisible: Binding<Bool>, hidesSeparator: Bool = false, showsClearAction: Bool = false, @ViewBuilder clearAction: () -> any View = { FioriIcon.actions.sysCancel.foregroundColor(.gray) }, componentIdentifier: String? = DateTimePicker.identifier) -
init(title:valueLabel: controlState: errorMessage: range: selectedDate: dateFormatter: pickerComponents: dateStyle: timeStyle: noDateSelectedString: pickerVisible: hidesSeparator: ) Convenience initializer for
DateTimePickerDeclaration
Swift
init(@ViewBuilder title: () -> any View, @ViewBuilder valueLabel: () -> any View = { EmptyView() }, controlState: ControlState = .normal, errorMessage: AttributedString? = nil, range: ClosedRange<Date>? = nil, selectedDate: Binding<Date?> = .constant(nil), dateFormatter: DateFormatter? = nil, pickerComponents: DatePicker.Components = [.date, .hourAndMinute], dateStyle: Date.FormatStyle.DateStyle = .abbreviated, timeStyle: Date.FormatStyle.TimeStyle = .shortened, noDateSelectedString: String? = nil, pickerVisible: Binding<Bool>, hidesSeparator: Bool = false)Parameters
titleThe title view for the date time picker.
valueLabelThe value view for the date time picker.
controlStateThe
ControlStateof the form view. The default isnormal.errorMessageThe error message of the form view.
rangeThe inclusive range of selectable dates.
selectedDateThe date value being displayed and selected.
dateFormatterThe
DateFormatterto be used to display the selectedDate. Default formatter will use customized dateStyle and timeStyle.pickerComponentsThe components shown in the date picker, default value shows date and time.
dateStyleThe custom style for displaying the date. The default value is
.abbreviated, showing for example, “Oct 21, 2015”.timeStyleThe custom style for displaying the time. The default value is
.shortened, showing for example, “4:29 PM” or “16:29”.noDateSelectedStringThe text to be displayed when no date is selected. If this property is
nil, the localized string “No date selected” will be used.pickerVisibleThis property indicates whether the picker is to be displayed.
hidesSeparatorThis property indicates whether the separator is to be displayed. Default is false.
-
init(title:valueLabel: mandatoryFieldIndicator: isRequired: controlState: errorMessage: range: selectedDate: dateFormatter: pickerComponents: dateStyle: timeStyle: noDateSelectedString: pickerVisible: hidesSeparator: ) Convenience initializer for
DateTimePickerDeclaration
Swift
init(title: AttributedString, valueLabel: AttributedString? = nil, mandatoryFieldIndicator: TextOrIcon? = .text("*"), isRequired: Bool = false, controlState: ControlState = .normal, errorMessage: AttributedString? = nil, range: ClosedRange<Date>? = nil, selectedDate: Binding<Date?>, dateFormatter: DateFormatter? = nil, pickerComponents: DatePicker.Components = [.date, .hourAndMinute], dateStyle: Date.FormatStyle.DateStyle = .abbreviated, timeStyle: Date.FormatStyle.TimeStyle = .shortened, noDateSelectedString: String? = nil, pickerVisible: Binding<Bool>, hidesSeparator: Bool = false)Parameters
titleThe title string for the date time picker.
valueLabelThe value string for the date time picker.
mandatoryFieldIndicatorThe mandatory field indicator for the date time picker.
isRequiredThis property indicates whether the mandatory field indicator is to be displayed.
controlStateThe
ControlStateof the form view. The default isnormal.errorMessageThe error message of the form view.
rangeThe inclusive range of selectable dates.
selectedDateThe date value being displayed and selected.
dateFormatterThe
DateFormatterto be used to display the selectedDate. Default formatter will use customized dateStyle and timeStyle.pickerComponentsThe components shown in the date picker, default value shows date and time.
dateStyleThe custom style for displaying the date. The default value is
.abbreviated, showing for example, “Oct 21, 2015”.timeStyleThe custom style for displaying the time. The default value is
.shortened, showing for example, “4:29 PM” or “16:29”.noDateSelectedStringThe text to be displayed when no date is selected. If this property is
nil, the localized string “No date selected” will be used.pickerVisibleThis property indicates whether the picker is to be displayed.
hidesSeparatorThis property indicates whether the separator is to be displayed. Default is false.
-
Undocumented
Declaration
Swift
static let identifier: String -
init(title:valueLabel: mandatoryFieldIndicator: isRequired: controlState: errorMessage: range: selectedDate: dateFormatter: pickerComponents: dateStyle: timeStyle: noDateSelectedString: pickerVisible: hidesSeparator: showsClearAction: clearAction: ) Undocumented
Declaration
Swift
init(title: AttributedString, valueLabel: AttributedString? = nil, mandatoryFieldIndicator: TextOrIcon? = .text("*"), isRequired: Bool = false, controlState: ControlState = .normal, errorMessage: AttributedString? = nil, range: ClosedRange<Date>? = nil, selectedDate: Binding<Date?>, dateFormatter: DateFormatter? = nil, pickerComponents: DatePicker.Components = [.date, .hourAndMinute], dateStyle: Date.FormatStyle.DateStyle = .abbreviated, timeStyle: Date.FormatStyle.TimeStyle = .shortened, noDateSelectedString: String? = nil, pickerVisible: Binding<Bool>, hidesSeparator: Bool = false, showsClearAction: Bool = false, @ViewBuilder clearAction: () -> any View = { FioriIcon.actions.sysCancel.foregroundColor(.gray) }) -
Undocumented
Declaration
Swift
init(_ configuration: DateTimePickerConfiguration) -
Declaration
Swift
@MainActor public var body: some View { get } -
Undocumented
Declaration
Swift
public var isEmpty: Bool { get }