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 }  
相關文章
相關標籤/搜索