时间选择器
来源:互联网 发布:在线考试数据库设计 编辑:程序博客网 时间:2024/05/17 01:18
let alertController:UIAlertController=UIAlertController(title:"\n\n\n\n\n\n\n\n\n", message: nil, preferredStyle: UIAlertControllerStyle.actionSheet)
// 初始化 datePicker
let datePicker =UIDatePicker( )
//将日期选择器区域设置为中文,则选择器日期显示为中文
datePicker.locale =NSLocale(localeIdentifier:"zh_CN")asLocale
// 设置样式,当前设为同时显示日期和时间
datePicker.datePickerMode =UIDatePickerMode.date
// 设置默认时间
datePicker.date =NSDate()asDate
// 响应事件(只要滚轮变化就会触发)
// datePicker.addTarget(self, action:Selector("datePickerValueChange:"), forControlEvents: UIControlEvents.ValueChanged)
alertController.addAction(UIAlertAction(title:"确定", style:UIAlertActionStyle.default){
(alertAction)->Voidin
//更新提醒时间文本框
let formatter =DateFormatter()
//日期样式
formatter.dateFormat ="yyyy-MM-dd"
self.labStartTime.text=formatter.string(from: datePicker.date)
})
alertController.addAction(UIAlertAction(title:"取消", style:UIAlertActionStyle.cancel,handler:nil))
alertController.view.addSubview(datePicker)
self.present(alertController, animated:true, completion:nil)
方式二:使用ActionSheetPicker-3.0
https://github.com/skywinder/ActionSheetPicker-3.0#cocoapods
let picker=ActionSheetDatePicker(title:"", datePickerMode:UIDatePickerMode.date, selectedDate:NSDate()asDate!, doneBlock: { picker, value, indexin
//更新提醒时间文本框
let formatter =DateFormatter()
//日期样式
formatter.dateFormat ="yyyy-MM-dd"
self.labStartTime.text=formatter.string(from: value as! Date)
return
}, cancel: { ActionStringCancelBlock in return }, origin:self.viewStartTime)
picker?.setDoneButton(UIBarButtonItem(title:"确认", style:UIBarButtonItemStyle.plain, target:self, action:nil))
picker?.setCancelButton(UIBarButtonItem(title:"取消", style:UIBarButtonItemStyle.plain, target:self, action:nil))
picker?.show()
- 时间选择器
- 时间选择器
- 时间选择器
- 时间选择器
- 时间选择器
- 时间选择器
- 时间选择器
- 时间选择器
- 时间选择器
- 时间选择器
- 时间选择器
- 时间选择器
- 时间选择器
- 时间选择器
- 时间选择器
- 时间选择器和日期选择器
- [Android]时间选择器/日历选择器/选择器dialog
- 时间选择器----js
- 重载(overload)和重写(overied,有的书也叫作“覆盖”)的区别?
- Action 动作
- 解决文件嵌套太深无法删除问题。
- 随机生成中文姓名,性别,Email,手机号,住址
- Android开发初级(二)——开发环境搭建
- 时间选择器
- HADOOP基本操作命令
- android开发如何获取res/raw和assets文件夹的路径
- HDU 1698 Just a Hook (线段树的区间更新)
- 超详细单机版搭建hadoop环境图文解析
- js各类方法示例
- gson和json-lib的区别
- openstack的虚拟机网卡、网桥等(tap、qbr、qvb、qvo)mtu设置
- .net反射详解