码迷,mamicode.com
首页 > 其他好文 > 详细

UIDatePickerView实现时间滚动轮播效果

时间:2016-06-06 16:37:36      阅读:139      评论:0      收藏:0      [点我收藏+]

标签:

 1 - (void)viewDidLoad  
 2 {  
 3     [super viewDidLoad];  
 4     // Do any additional setup after loading the view.  
 5     self.title = @"第二页";  
 6     self.view.backgroundColor = [UIColor orangeColor];  
 7       
 8     UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 460)];  
 9     view = self.view;  
10     UIDatePicker *datePicker = [[UIDatePicker alloc] initWithFrame:CGRectMake(0, 80, 320, 300)];  
11     datePicker.backgroundColor = [UIColor magentaColor];  
12     datePicker.date = [NSDate date];  
13     datePicker.datePickerMode = UIDatePickerModeDateAndTime;  
14     [view addSubview:datePicker];  
15       
16     // 添加一个按钮  
17     UIButton *button = [UIButton buttonWithType:UIButtonTypeRoundedRect];  
18     button.frame = CGRectMake(100, 300, 120, 50);  
19     [button setTitle:@"时间" forState:UIControlStateNormal];  
20     [button addTarget:self action:@selector(buttonEventMathod:) forControlEvents:UIControlEventTouchDown];  
21     [self.view addSubview:button];  
22       
23     [view release];  
24 }  
25 -(void)buttonEventMathod:(UIButton *)button  
26 {  
27     UIDatePicker *picker = (UIDatePicker *)[self.view viewWithTag:100];  
28     NSDateFormatter *formatter = [[NSDateFormatter alloc] init];  
29     formatter.dateFormat = @"YYYY-MM-DD hh:mm:ss-aa";  
30     NSLog(@"格式化时间:%@", [formatter stringFromDate:picker.date]);  
31 }  

 

UIDatePickerView实现时间滚动轮播效果

标签:

原文地址:http://www.cnblogs.com/-Eric-Liu/p/5564048.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!