使用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
关于日期按钮的外观绘制详见上一节,点击按钮的响应事件为:
[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
相关文章推荐
- swift开发笔记11 - 使用UIAlertController在底部弹出日期选择框
- android日期选择器,从底部弹出的日期选择器,有点像IOS日期选择器
- iOS8底部弹出日期选择或自定义选择器的方法
- QCalendar的使用:实现弹出日历选择日期的例子
- 还是mui的日期选择插件使用,可以在弹出日期选择之前提问他是否想修改
- vue里面使用mui的弹出日期选择插件
- vue里面使用mui的弹出日期选择插件实例
- Android AndBase框架之底部弹出日期选择器
- bootstrap datepicker 与bootstrapValidator同时使用时选择日期后无法正常触发校验的解决思路
- Combobox的使用,日期选择器
- Vue.js中使用iView日期选择器并设置开始时间结束时间校验功能
- PopupWindow实现从底部弹出或滑出选择菜单或窗口
- IOS 日期选择器 UIDatePicker的使用
- My97DatePicker 日期选择器,使用的时候,如果IE6下打开使用该控件的html会出错 “无法打开站点,已终止操作”
- Js 日期选择,可以的一个页面中重复使用本JS日历,兼容IE及火狐等主流浏览器,而且界面简洁、美观,操作体验也不错。
- 使用datepicker插件实现日期选择的基本操作 8-5
- android 点击EditText 弹出日期选择器DatePickerDialog
- 解决安卓上底部使用fixed布局,键盘弹出后fixed部分的内容挡住form表单的情况
- daterangepicker bootstarp 日期范围选择控件使用注意事项
- js 点击文本框后弹出选择日期