Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to hide days in UIDatePicker

How to hide days in UIDatePicker and add Done button in the UIDatePicker.

enter image description here

like image 413
Ramprasath Selvam Avatar asked Dec 08 '25 10:12

Ramprasath Selvam


1 Answers

There is no way to do it using UIDatePicker, you've to use the custom library or your own created custom view.

Use this Library MonthYearPickerView-Swift:

Add MonthYearPickerView.swift file to your project and use:

let monthYearPickerView = MonthYearPickerView()
monthlyPickerView.onDateSelected = { (month: Int, year: Int) in
    let string = String(format: "%02d/%d", month, year)
    NSLog(string) // should show something like 05/2015
}
monthYearPickerView.frame = CGRect(frame)
view.addSubview(monthYearPickerView)

Note: Add your own toolbar on top of PickerView.

Output:

enter image description here

Hope it helps.

like image 82
Imad Ali Avatar answered Dec 11 '25 00:12

Imad Ali



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!