时间选择器机获取上边时间
2016-02-18 17:35
260 查看
创建datePicker
_datapicg =[[UIDatePicker
alloc] initWithFrame:CGRectMake(0,
0, timeBaseView.bounds.size.width, timeBaseView.bounds.size.height-30)];
[timeBaseView addSubview:_datapicg];
_datapicg.backgroundColor =[UIColor
whiteColor];
// 设置区域为中国简体中文
_datapicg.locale = [[NSLocale
alloc] initWithLocaleIdentifier:@"zh_CN"];
//
设置picker的显示模式:只显示日期
_datapicg.datePickerMode =
UIDatePickerModeDate;
// 10.3UIDatePicker需要监听值的改变
[_datapicg
addTarget:self
action:@selector(dateChange)forControlEvents:UIControlEventValueChanged];
dateChange 这个方法是滑动时间的滚动条的事后调用的停止之后就开始调用这个方法;
获取datePIcker的时间
NSDate *myDate =
_datapicg.date;
NSDateFormatter *dateFormat = [[NSDateFormatter
alloc] init];
[dateFormat setDateFormat:@"YYYY.MM.DD"];
NSString *prettyVersion = [dateFormat
stringFromDate:myDate];
NSLog(@"%@",prettyVersion);
[self
removeFromSuperview];
_datapicg =[[UIDatePicker
alloc] initWithFrame:CGRectMake(0,
0, timeBaseView.bounds.size.width, timeBaseView.bounds.size.height-30)];
[timeBaseView addSubview:_datapicg];
_datapicg.backgroundColor =[UIColor
whiteColor];
// 设置区域为中国简体中文
_datapicg.locale = [[NSLocale
alloc] initWithLocaleIdentifier:@"zh_CN"];
//
设置picker的显示模式:只显示日期
_datapicg.datePickerMode =
UIDatePickerModeDate;
// 10.3UIDatePicker需要监听值的改变
[_datapicg
addTarget:self
action:@selector(dateChange)forControlEvents:UIControlEventValueChanged];
dateChange 这个方法是滑动时间的滚动条的事后调用的停止之后就开始调用这个方法;
获取datePIcker的时间
NSDate *myDate =
_datapicg.date;
NSDateFormatter *dateFormat = [[NSDateFormatter
alloc] init];
[dateFormat setDateFormat:@"YYYY.MM.DD"];
NSString *prettyVersion = [dateFormat
stringFromDate:myDate];
NSLog(@"%@",prettyVersion);
[self
removeFromSuperview];
相关文章推荐
- Rapid Design Visualization v2007-ISO 1CD(工程设计仿真)
- PHP 用户名、邮箱、手机账号中间字符串以*隐藏
- Xcode 6制作动态及静态通用Framework(解决不支持 armv7s arm64 armv7)
- 2.8 Android 产品统计 报表 好用的“友盟”
- Retinex图像增强算法
- 常见的media断点
- mysql日志详细解析
- HaProxy+Keepalived+Mycat高可用群集配置
- 自制简单的.Net ORM框架 (一) 简介
- EF相关知识
- monoDB环境搭建
- ACM刷题常用链接
- [安卓开发工具]
- Terrasolid Suite v015-v016 for Microstation CONNECT, V8i, V8 & for Windows platforms 1CD
- jquery 对 Json 的各种遍历
- javascript二维数组遍历
- 校验下载的文件
- ASP.NET学习
- 宏参数
- Sublime