您的位置:首页 > 产品设计 > UI/UE

使用UIAlertController在底部弹出日期选择框

2016-10-09 11:24 405 查看
点击日期按钮,弹出一个日期选择框在底部,选完日期后,修改日期按钮上的文字:







关于日期按钮的外观绘制详见上一节,点击按钮的响应事件为:

[objc] view
plain copy

@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)  

       // 初始化 datePicker  

       let datePicker = UIDatePicker( )  

       //将日期选择器区域设置为中文,则选择器日期显示为中文  

       datePicker.locale = NSLocale(localeIdentifier: "zh_CN")  

       // 设置样式,当前设为同时显示日期和时间  

       datePicker.datePickerMode = UIDatePickerMode.Date  

       // 设置默认时间  

       datePicker.date = NSDate()  

       // 响应事件(只要滚轮变化就会触发)  

       // datePicker.addTarget(self, action:Selector("datePickerValueChange:"), forControlEvents: UIControlEvents.ValueChanged)  

       alertController.addAction(UIAlertAction(title: "确定", style: UIAlertActionStyle.Default){  

           (alertAction)->Void in  

           print("date select: \(datePicker.date.description)")  

           //获取上一节中自定义的按钮外观DateButton类,设置DateButton类属性thedate  

           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
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐