bendodson / MonthYearWheelPicker

A UIPickerView subclass that allows you to quickly add a picker for just month and year; in most cases it can be used as a drop-in replacement for UIDatePicker.
https://bendodson.com
The Unlicense
183 stars 42 forks source link

How to implement? #7

Closed xuanzi23 closed 7 years ago

xuanzi23 commented 7 years ago

Hi, i have download your file and copy in to my project. But somehow I not manage to implement it. let ChooseYear: UITapGestureRecognizer = UITapGestureRecognizer(target: self ,action: #selector(self.ChooseYearr)) self.yearLabel.addGestureRecognizer(ChooseYear) yearLabel.isUserInteractionEnabled = true

func ChooseYearr(){ let expiryDatePicker = MonthYearPickerView() expiryDatePicker.onDateSelected = { (month: Int, year: Int) in let string = String(format: "%02d/%d", month, year) NSLog(string) // should show something like 05/2015 } }

Why?

bendodson commented 7 years ago

You'll need to actually attach the MonthYearPickerView to something be that adding it as a subview to your UIView or by using it as an input with a keyboard. This is basically a drop-in replacement for UIPickerView() so whatever you would do to present a picker is what you should do to present this.