So far I've only found date-picker bound to UITextField
, but I need a date-picker which opens on UIButton
tap in the same way as it does with the UITextField
.
Is it possible? And if so, how? Thanks in advance.
@IBAction func BtnClicked(sender: AnyObject) {
var picker : UIDatePicker = UIDatePicker()
picker.datePickerMode = UIDatePickerMode.Date
picker.addTarget(self, action: "dueDateChanged:", forControlEvents: UIControlEvents.ValueChanged)
var pickerSize : CGSize = picker.sizeThatFits(CGSizeZero)
picker.frame = CGRectMake(0.0, 250, pickerSize.width, 460)
// you probably don't want to set background color as black
// picker.backgroundColor = UIColor.blackColor()
self.view.addSubview(picker)
}
func dueDateChanged(sender:UIDatePicker){
var dateFormatter = NSDateFormatter()
dateFormatter.dateStyle = NSDateFormatterStyle.LongStyle
dateFormatter.timeStyle = NSDateFormatterStyle.NoStyle
self.myLabel.text = dateFormatter.stringFromDate(dueDatePickerView.date)
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With