UIDatePickerView实现时间滚动轮播效果

 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 }  

 

posted @ 2016-06-06 15:49  超级马力  阅读(577)  评论(0编辑  收藏  举报