UIDatePicker的运用
来源:互联网 发布:编程工具排行榜 编辑:程序博客网 时间:2024/05/17 03:21
- (IBAction)SetTime1:(UIButton *)sender {
[selfSelectTime1];
}
-(void)SelectTime1{
UIView *bgView = [[UIViewalloc] initWithFrame:self.view.bounds];
_pickBgView = bgView;
UITapGestureRecognizer *tapGes = [[UITapGestureRecognizeralloc] initWithTarget:selfaction:@selector(removeBgView)];
bgView.userInteractionEnabled =YES;
[bgView addGestureRecognizer:tapGes];
[self.viewaddSubview:bgView];
UIDatePicker *datePicker; datePicker = [[UIDatePickeralloc] initWithFrame:CGRectMake(0,ViewHeight+20,ViewWidth, 150)];
datePicker.datePickerMode =UIDatePickerModeDate;
datePicker.date = [NSDatedate];
[_pickBgView addSubview:datePicker];
//添加事件
[datePicker addTarget:selfaction:@selector(clickDatePicker1:)forControlEvents:UIControlEventValueChanged];
//设置最小日期为现在的日期
[datePicker setMinimumDate:[NSDatedate]];
//设置最大日期为2020-01-01
NSDateFormatter *format = [[NSDateFormatteralloc] init];
[format setDateFormat:@"yyyy-MM-dd"];
NSDate *MaxDate = [format dateFromString:@"2020-01-01"];
[datePicker setMaximumDate:MaxDate];
_datePicker = datePicker;
//设置为中文显示
NSLocale *locale = [[NSLocalealloc] initWithLocaleIdentifier:@"zh_CN"];
datePicker.locale = locale;
datePicker.backgroundColor = [UIColorwhiteColor];
[UIViewanimateWithDuration:0.5animations:^{
datePicker.frame = CGRectMake(0, ViewHeight-80, ViewWidth, 150);
}];
}
#pragma mark - 点击时间选择器
- (void)clickDatePicker1:(UIDatePicker *)sender
{
NSDate *date = sender.date;
NSDateFormatter *format = [[NSDateFormatteralloc] init];
// [format setDateFormat:@"yyyy-MM-dd"];
[format setDateFormat:@"MM月dd日"];
NSString *dateString = [format stringFromDate:date];
//设置后台传递的时间戳
NSString *timeSp = [NSStringstringWithFormat:@"%ld",(long)[sender.datetimeIntervalSince1970]];
//改变日期的字符串数据时间戳参数
NSLog(@"dateString %@",timeSp);
// 设置界面显示的文字
self.TimeLab1.text=dateString;
}
#pragma mark - 移除选择时间视图
- (void)removeBgView
{
[UIViewanimateWithDuration:0.5animations:^{
_datePicker.frame =CGRectMake(0,ViewHeight+100,ViewWidth, 150);
[selfperformSelector:@selector(afterAction)withObject:nilafterDelay:1];
}];
}
//移除PickerView
- (void)removePickerView
{
[UIViewanimateWithDuration:0.5animations:^{
_pickView.frame =CGRectMake(0,ViewHeight+100,ViewWidth, 150);
[selfperformSelector:@selector(afterAction)withObject:nilafterDelay:1];
}];
//移除视图
}
- (void)afterAction
{
[_pickBgViewremoveFromSuperview];
}
- UIDatePicker的运用
- UIDatePicker简单运用
- UIDatePicker的使用
- UIDatePicker的使用
- UIDatePicker的简单设置
- UIDatePicker的简单用法
- UIDatePicker 的使用
- UIDatePicker的用法
- UIDatePicker的使用
- UIDatePicker的使用
- 简述UIDatePicker的用法
- UIDatePicker的用法
- 自定义简单的UIDatePicker
- UIDatePicker的简单使用
- 简述UIDatePicker的用法
- UIDatePicker的简单用法
- UIDatePicker的使用
- UIDatePicker 高度的设置
- 二分查找算法
- hibernate单向关联与双向关联
- 常见的关系数据库
- 归并排序算法
- Android 项目选择SDK解释
- UIDatePicker的运用
- Linux下10个ps命令的基本例子
- 卷纸快速抽调纸筒
- 图书管理系统c++
- 我的文件夹下面有汉字的路径,matlab 不识别
- 快速排序算法
- poj3169(差分约束)
- 深入理解Android之Gradle
- 话说十年