It is a sublcass of UIPickerView. You can display month and year using native iOS control.
You can use Swift Package Manager to add MonthYearDatePicker to your Xcode project. Select File » Add Packages Dependencies... and enter the repository URL https://github.com/IgorFedorchuk/MonthYearDatePicker.git into the search bar (top right).
- iOS 13.0
- Xcode 15.0+
- iPhone/iPad
- Swift 5
For clearer comprehension, please open the project located in the "Example" folder.
var picker = DatePickerView(frame: view.bounds)
picker.needRecenter = true
picker.minYear = 2020
picker.maxYear = 2030
picker.rowHeight = 60
picker.yearFont = UIFont.systemFont(ofSize: 17)
picker.monthFont = UIFont.systemFont(ofSize: 17)
picker.locale = Locale(identifier: "en_US")
picker.onYearChanged = { year in
print("year: \(year)")
print("date: \(String(describing: picker.date))")
}
picker.onMonthChanged = { index, name in
print("name: \(name), index: \(index)")
print("date: \(String(describing: picker.date))")
}
view.addSubview(picker)
picker.reloadAllComponents()
picker.selectToday()