简体   繁体   English

MonthYearPickerView中的错误

[英]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. 因此,我遵循了这个线程: 如何在iOS中使用DatePicker仅接受月份和年份,并建议我在github中使用MonthYearPickerView-Swift

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 呼叫中缺少参数'frame'的参数

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. 任何帮助,将不胜感激。

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. 错误是说您需要将frame作为参数标签传递给init ,因此您需要调用init(frame:)并传递CGRect实例。

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. 注意:根据您的视图传递CGRect实例。

You need to give the frame of MonthYearPickerView and add this view to View where you want to have it or see it. 您需要提供MonthYearPickerView的框架,并将此视图添加到要拥有或查看它的“视图”中。

let hightOfMonthYearPickerView: CGFloat = 200
let frame = CGRect(x: 0, y: 0, width: self.view.frame.width, height: hightOfMonthYearPickerView)
let expiryDatePicker = MonthYearPickerView()
expiryDatePicker.frame = frame
expiryDatePicker.onDateSelected = { (month: Int, year: Int) in
    let string = String(format: "%02d/%d", month, year)
    print(string) // 05/2015
}
mainView.addSubview(expiryDatePicker)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM