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 }  

 

转载于:https://www.cnblogs.com/-Eric-Liu/p/5564048.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值