点击日期按钮,弹出一个日期选择框在底部,选完日期后,修改日期按钮上的文字:



关于日期按钮的外观绘制详见上一节,点击按钮的响应事件为:
- @IBAction func selectDate(sender: AnyObject) {
-
- let alertController:UIAlertController=UIAlertController(title: "\n\n\n\n\n\n\n\n\n\n\n\n", message: nil, preferredStyle: UIAlertControllerStyle.ActionSheet)
-
- let datePicker = UIDatePicker( )
-
- datePicker.locale = NSLocale(localeIdentifier: "zh_CN")
-
- datePicker.datePickerMode = UIDatePickerMode.Date
-
- datePicker.date = NSDate()
-
-
- alertController.addAction(UIAlertAction(title: "确定", style: UIAlertActionStyle.Default){
- (alertAction)->Void in
- print("date select: \(datePicker.date.description)")
-
- let myDateButton=self.Datebutt as? DateButton
- myDateButton?.thedate=datePicker.date
-
- myDateButton?.setNeedsDisplay()
- })
- alertController.addAction(UIAlertAction(title: "取消", style: UIAlertActionStyle.Cancel,handler:nil))
-
- alertController.view.addSubview(datePicker)
-
- self.presentViewController(alertController, animated: true, completion: nil)
- }
转自:http://blog.csdn.net/baixiaozhe/article/details/48974497