UIDatePicker 时间滚动表
2015-12-19 11:12
453 查看
UIDatePicker *datapicker; //时间滚动表
datapicker = [[UIDatePicker alloc]initWithFrame:CGRectMake(50, 200, 250, 100)];
datapicker.datePickerMode = UIDatePickerModeDate;
NSLocale *locale = [[NSLocale alloc] initWithLocaleIdentifier:@"zh_CN"];
datapicker.locale = locale;
NSDate *select = datapicker.date;
datapicker.maximumDate =select;
[datapicker addTarget:self action:@selector(agepicker) forControlEvents:UIControlEventValueChanged];
[informationView addSubview:datapicker];
agelabel = [[UILabel alloc]initWithFrame:CGRectMake(0, 55, Kwidth, 25)];
agelabel.backgroundColor = [UIColor redColor];
agelabel.textAlignment = NSTextAlignmentLeft;
[informationView addSubview:agelabel];
#pragma mark - 得到年龄
-(void)agepicker{
NSDate *select = datapicker.date;
NSTimeInterval dateDiff = [select timeIntervalSinceNow];
int age=-trunc(dateDiff/(60*60*24))/365;//这是根据年月日计算出年龄的一个函数 我的计算出来时是一个负值 直接在前面加了一个负号 也没去管他
NSLog(@"年龄%d",age);
agelabel.text = [NSString stringWithFormat:@"%d",age];
这一是显示具体的年月日
NSDate *select = datapicker.date;
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setDateFormat:@"yyyy-MM-dd"];
NSString *dateAndTime = [dateFormatter stringFromDate:select];
label.text = [NSString stringWithFormat:@"%@",dateAndTime];//这是自己做地一个label来显现年月日
}
datapicker = [[UIDatePicker alloc]initWithFrame:CGRectMake(50, 200, 250, 100)];
datapicker.datePickerMode = UIDatePickerModeDate;
NSLocale *locale = [[NSLocale alloc] initWithLocaleIdentifier:@"zh_CN"];
datapicker.locale = locale;
NSDate *select = datapicker.date;
datapicker.maximumDate =select;
[datapicker addTarget:self action:@selector(agepicker) forControlEvents:UIControlEventValueChanged];
[informationView addSubview:datapicker];
agelabel = [[UILabel alloc]initWithFrame:CGRectMake(0, 55, Kwidth, 25)];
agelabel.backgroundColor = [UIColor redColor];
agelabel.textAlignment = NSTextAlignmentLeft;
[informationView addSubview:agelabel];
#pragma mark - 得到年龄
-(void)agepicker{
NSDate *select = datapicker.date;
NSTimeInterval dateDiff = [select timeIntervalSinceNow];
int age=-trunc(dateDiff/(60*60*24))/365;//这是根据年月日计算出年龄的一个函数 我的计算出来时是一个负值 直接在前面加了一个负号 也没去管他
NSLog(@"年龄%d",age);
agelabel.text = [NSString stringWithFormat:@"%d",age];
这一是显示具体的年月日
NSDate *select = datapicker.date;
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setDateFormat:@"yyyy-MM-dd"];
NSString *dateAndTime = [dateFormatter stringFromDate:select];
label.text = [NSString stringWithFormat:@"%@",dateAndTime];//这是自己做地一个label来显现年月日
}
相关文章推荐
- SQLServer跨服务器访问数据库(openrowset/opendatasource/openquery)
- juery实现粘贴复制
- [IOS]轻松理解UITableViewCell的重用机制
- 308. Range Sum Query 2D - Mutable
- Android:Handler+Looper+MessageQueue+Thread(线程间的通信)随记
- 【Java学习笔记】String、StringBuffer和StringBuilder
- mysql update中使用subquery
- 【POJ 3709】K-Anonymous Sequence
- jenkins 安装 SVN Publisher 后向 svn 提交代码报错: E170001: Authentication required for...
- Query on a tree II
- 2016扁平化图标设计如何做太原UI设计师郭文军讲
- ERROR: Error installing rails: ERROR: Failed to build gem native extension.
- Leetcode: Implement Stack using Queues
- Storyboard应用:快速创建及设置View
- ios学习之UI控件的一些基本使用
- UITableView实现选中一行或者多行
- 使用druid配置jndi
- Arduino 中多传感器数据采集的写法
- Permutation Sequence
- [知识点随笔] UIView--transform 属性