UIDatePickerView实现时间滚动轮播效果

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了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 }  

 

以上是关于UIDatePickerView实现时间滚动轮播效果的主要内容,如果未能解决你的问题,请参考以下文章

天猫京东app中常见的上下滚动轮播效果如何实现?

无限滚动轮播(仅限 CSS)

JS纯生实现无缝滚动轮播图

防止 Flutter WebView 溢出水平滚动轮播?

js 实现横向滚动轮播并中间暂停下

H5滚动轮播插件