[英]Date Picker swift iOS
So I have my date picker set up as 所以我将日期选择器设置为
func configurePicker()
{
pickerContainer.frame = CGRectMake(0.0, 600.0, 320.0, 300.0)
pickerContainer.backgroundColor = UIColor(red: 6/225.0, green: 232/225.0, blue: 255/225.0, alpha: 0)
picker.frame = CGRectMake(0.0, 20.0, 320.0, 300.0)
let dateComponents = NSDateComponents()
dateComponents.year = -18
let dateComponents2 = NSDateComponents()
dateComponents2.year = -60
picker.maximumDate = NSCalendar.currentCalendar().dateByAddingComponents(dateComponents, toDate: NSDate(), options: nil)
picker.minimumDate = NSCalendar.currentCalendar().dateByAddingComponents(dateComponents2, toDate: NSDate(), options: nil)
picker.setDate(picker.maximumDate!, animated: true)
picker.datePickerMode = UIDatePickerMode.Date
pickerContainer.addSubview(picker)
}
as you can tell I have a minimum and maximum date set up. 如您所知,我设置了一个最小和最大日期。 I also have a dismiss function I did not include. 我也有一个不包含的解除功能。 My question is how can I find out when the user is below the minimum and above maximum? 我的问题是如何找出用户低于最小值和最大值的情况? What I want to do is play a gif in the background when the user is below the minimum and a separate gif when above the maximum? 我想做的是,当用户低于最小值时在后台播放gif,而高于最大值时单独播放gif? is there a way to tell where the user is on the date picker wheel? 有没有办法告诉用户日期选择轮上的位置? I understand that the date picker wheel resets past the minimum and maximum but i just want to know if there is a way to know what date the wheel is at without the user letting go. 我知道日期选择器轮会重置超过最小值和最大值,但是我只想知道是否有一种方法可以知道轮在什么日期而不被用户放开。 For example a conditional statement like this that works 例如,这样的条件语句有效
if(picker.date > picker.maximumDate)
{
playgif1()
}
else if(picker.date < picker.minimumDate)
{
playgif2()
}
Above comparisons do not work gives me an error keeps saying cannot find overload for '>' or '<' 上面的比较不起作用给我一个错误,总是说找不到'>'或'<'的重载
Thank You for any help 感谢您的任何帮助
As far as I know, unless Apple added a new API, UIDatePicker (and UIPickerView in general), do not have methods to get scroll events from them. 据我所知,除非Apple添加了新的API,UIDatePicker(通常是UIPickerView),否则没有方法从中获取滚动事件。
I think the best you can do is to add a target method to the picker for a ValueChanged event, which will call a method when the user has stopped scrolling on a date. 我认为您最好的办法是为ValueChanged事件的选择器添加目标方法,当用户停止在日期上滚动时,该方法将调用该方法。
func configurePicker() {
//...other configuration
picker.addTarget(self, action: "datePicked:", forControlEvents: UIControlEvents.ValueChanged)
}
func datePicked(picker: UIDatePicker) {
// compare dates
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.