Search code examples
iosswiftuidatepicker

Error in MonthYearPickerView


I need to implement date picker for expire date only with month and year in swift. So I follow this thread How to accept only Month and Year using DatePicker in iOS and as it suggest I used MonthYearPickerView-Swift in github.

I add that subclass to my application and implement the code as

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
}

But I have an error in first line as

Missing argument for parameter 'frame' in call

Can anyone (who used this earlier)help me to solve this? Or any other way to create date picker only for month and year?

Any help would be appreciated.


Solution

  • Error is saying that you need to pass the frame as argument label with init, so you need to call init(frame:) and passed CGRect instance.

    let expiryDatePicker = MonthYearPickerView(frame: CGRect(x: 0, y: 0, width: self.view.frame.size.width, height: 170))
    

    Note: Pass CGRect instance according to your view.