1

I'm using CalendarKit and SwiftUI. I need to create "Today" button and Date Picker to select date, but I didn't foudn any solution, so is there a way to change the date or call somethign like move(to date: Date) function from another view?

  • What have you tried? A minimal reproducible product will get you better answers. https://stackoverflow.com/help/minimal-reproducible-example – lorem ipsum Dec 11 '20 at 17:38
  • I don't think an example is needed. This is a question for the CalendarKit library. – Даниил Кикимов Dec 12 '20 at 07:33
  • https://stackoverflow.com/help/how-to-ask – lorem ipsum Dec 12 '20 at 14:41
  • I suggest you coding your "change date" logic in UIKit for now and then exposing the CalendarKit to SwiftUI as explained in this answer: https://stackoverflow.com/questions/64432749/can-i-use-view-controller-calendarkit-in-swiftui-application This is until CalendarKit gets full SwiftUI support. Richard, CalendarKit creator – Richard Topchii Dec 19 '20 at 07:58

1 Answers1

1

Here's the solution I'm using

var customDayView: DayView?


class CustomCalendarExampleController: DayViewController {
  ....
   
    override func loadView() {
        .....
        customDayView = dayView
        ...
    }
}


func moveDate(_ date: Date) {
        let offsetDate = dateOnly(date: date, calendar: customDayView!.calendar)
        customDayView!.state?.move(to: offsetDate)
    }
  • Looks good, but why do you keep the `customDayView` outside of the `CustomCalendarExampleController`? You can just tie it's lifecycle to that of VC and create it in the `loadView ` method – Richard Topchii Dec 19 '20 at 23:12