We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Following the example in the README, I can't seem to get the selected day when using a custom dayItemProvider view.
Here is the full code:
class ViewController: UIViewController { override func viewDidLoad() { super.viewDidLoad() // Do any additional setup after loading the view. let calendarView = CalendarView(initialContent: makeContent()) calendarView.backgroundColor = .black calendarView.translatesAutoresizingMaskIntoConstraints = false view.addSubview(calendarView) NSLayoutConstraint.activate([ calendarView.leadingAnchor.constraint(equalTo: view.layoutMarginsGuide.leadingAnchor), calendarView.trailingAnchor.constraint(equalTo: view.layoutMarginsGuide.trailingAnchor), calendarView.topAnchor.constraint(equalTo: view.layoutMarginsGuide.topAnchor), calendarView.bottomAnchor.constraint(equalTo: view.bottomAnchor, constant: -(view.bounds.height * 0.3)), ]) calendarView.daySelectionHandler = { [weak self] day in print("day \(day)") } } private func makeContent() -> CalendarViewContent { let calendar = Calendar.current let date = Date() let components = calendar.dateComponents([.year, .month, .day], from: date) let startDate = calendar.date(from: components)! return CalendarViewContent( calendar: calendar, visibleDateRange: startDate...startDate, monthsLayout: .vertical(options: VerticalMonthsLayoutOptions())) .dayItemProvider { day in var invariantViewProperties = ExampleView.InvariantViewProperties( font: UIFont.systemFont(ofSize: 18), textColor: .darkGray, backgroundColor: .clear) return ExampleView.calendarItemModel( invariantViewProperties: invariantViewProperties, content: .init(day: day)) } } } struct ExampleView: CalendarItemViewRepresentable { /// Properties that are set once when we initialize the view. struct InvariantViewProperties: Hashable { let font: UIFont let textColor: UIColor let backgroundColor: UIColor } /// Properties that will vary depending on the particular date being displayed. struct Content: Equatable { let day: DayComponents } static func makeView( withInvariantViewProperties invariantViewProperties: InvariantViewProperties) -> UILabel { let label = UILabel() label.backgroundColor = invariantViewProperties.backgroundColor label.font = invariantViewProperties.font label.textColor = invariantViewProperties.textColor label.textAlignment = .center label.clipsToBounds = true label.layer.cornerRadius = 12 return label } static func setContent(_ content: Content, on view: UILabel) { view.text = "\(content.day.day)" } }
The text was updated successfully, but these errors were encountered:
No branches or pull requests
Following the example in the README, I can't seem to get the selected day when using a custom dayItemProvider view.
Here is the full code:
The text was updated successfully, but these errors were encountered: