如何弹出UIDatePicker最好

UIDateicker并没有继承UIPickerView,它的宽度只有iphone的宽度,在ipad上直接显示出来非常不协调,所以苹果建议用UIPopoverViewController来显示,所以你可以在里面任意定制。

在iphone中显示需要手动配制动画,因为它只是一个视图。所以你有下面几种方式显示出一个UIDatePicker.

  • 使用UIView动画块从底部慢慢滑动上来
  • 嵌入到UIAlert或者UIActionSheet中
  • 将UIDateicker视图做为可输入控件的定制键盘,inputView.
  • 最后我的变态方案将两个UIDatePicker一起弹出,形成一个时间区域选择 
    •  1 NSLocale *locale = [[[NSLocale alloc] initWithLocaleIdentifier:@"am_ET"] autorelease];
       2     
       3     
       4     UIDatePicker *datePicker1 = [[[IoriDatePicker alloc] initWithFrame:CGRectMake(-80, 0, 0, 0)] autorelease];
       5     UIDatePicker *datePicker2 = [[[UIDatePicker alloc] initWithFrame:CGRectMake(-80, 0, 0, 0)] autorelease];
       6     CGRect frame = datePicker1.frame;
       7     frame.origin.y = -frame.size.height*0.1/2l;
       8     datePicker1.frame = frame;
       9     datePicker2.frame = frame;
      10     datePicker1.transform =  CGAffineTransformMakeScale (0.9, 0.9);
      11     datePicker2.transform =  CGAffineTransformMakeScale (0.9, 0.9);
      12     
      13     NSTimeZone *timeZone = [[NSTimeZone alloc] initWithName:@"Antarctica/Vostok"];
      14     NSCalendar *calendar = [NSCalendar currentCalendar];
      15     calendar.locale = locale;
      16     calendar.timeZone = timeZone;
      17     datePicker1.calendar = calendar;
      18     
      19     UIView *datePickerContaner = [[[UIView alloc] initWithFrame:CGRectMake(0, 30, 320, datePicker1.frame.size.height)] autorelease];
      20     UIView *datePickerView1 = [[[UIView alloc] initWithFrame:CGRectMake(0, 0, 160, datePickerContaner.frame.size.height)] autorelease];
      21     UIView *datePickerView2 = [[[UIView alloc] initWithFrame:CGRectMake(160, 0, 160, datePickerContaner.frame.size.height)] autorelease];
      22     datePickerView1.clipsToBounds = YES;
      23     datePickerView1.autoresizesSubviews = YES;
      24     datePickerView2.clipsToBounds = YES;
      25     datePickerView2.autoresizesSubviews = YES;
      26     datePickerView1.layer.borderWidth = 1;
      27     datePickerView1.layer.cornerRadius = 8;
      28     datePickerView2.layer.borderWidth = 1;
      29     datePickerView2.layer.cornerRadius = 8;
      30     [datePickerContaner addSubview:datePickerView1];
      31     [datePickerContaner addSubview:datePickerView2];
      32     
      33     
      34     datePicker1.datePickerMode = UIDatePickerModeTime;
      35     [datePickerView1 addSubview:datePicker1];
      36     
      37     
      38     datePicker2.datePickerMode = UIDatePickerModeTime;
      39     [datePickerView2 addSubview:datePicker2];

       

转载于:https://www.cnblogs.com/ioriwellings/archive/2013/01/28/2879558.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值