【问题标题】:SwiftUI - Use DatePicker GraphicalDatePickerStyle as a read-only calendarSwiftUI - 使用 DatePicker GraphicalDatePickerStyle 作为只读日历
【发布时间】:2021-05-23 20:08:24
【问题描述】:

我想显示一个标有一组日期的日历(它反映了用户在我的应用程序上一个月内安排的所有预订)。

我正在尝试在不创建日历组件或导入库的情况下执行此操作。所以,我在这里使用来自 SwiftUI 的 DatePicker 组件和这个配置:

DatePicker(
    "",
    selection: $date,
    displayedComponents: [.date])
.datePickerStyle(GraphicalDatePickerStyle())

可以用我的数据层上保留的所有天数填充此日历吗?

我想要的是类似于日历应用的功能:

【问题讨论】:

    标签: swift swiftui swiftui-datepicker


    【解决方案1】:

    相当棘手,但您可以声明绑定变量以将 date 值设置为旧值。

    var body: some View {
        let binding = Binding<Date> {
            self.date
        } set: { newDate in
            self.date = Date() // your old value
        }
    
        DatePicker(
            "",
            selection:binding,
            displayedComponents: [.date])
        .datePickerStyle(GraphicalDatePickerStyle())
    
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-01-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-12-31
      • 1970-01-01
      相关资源
      最近更新 更多