0

Does anyone know how to slide in a UIDatePicker with a Done button like the keyboard control? If so, can you share some sample code on how. Thanks

Bryan C
  • 1,594
  • 4
  • 16
  • 30

2 Answers2

1

I suggest you use a UIViewController, and show it modally.

Create UIViewController and setup the view with OK-button in Interface Builder, as you would for any view controller.

And display it using:

- (void)presentModalViewController:(UIViewController *)modalViewController 
                          animated:(BOOL)animated

You can set the root views background to clear if you want it transparent. And optionaly animate it to cemi-transparent black when the transition has finished. Something like this would work:

- (void)viewDidAppear:(BOOL)animated {
  if (animated) [UIView beginAnimations:@"fadeDark" context:NULL];
  self.view.backgroundColor = [UIColor colorWithWithe:0.0f alpha:0.5f];
  if (animated) [UIView commitAnimations];
}
PeyloW
  • 36,742
  • 12
  • 80
  • 99
  • Actually there's a problem with this approach regarding clear modal view controllers. Just thought I'd point it out for anyone else here who wasted a few hours on this approach. http://stackoverflow.com/questions/849458/transparent-modal-view-on-navigation-controller – kris Nov 06 '11 at 00:58
0

1.create a subclass of the UIButton class

2.redeclare inputview as read-write

@property (nonatomic, strong, readwrite) UIView *inputView;

3.set canBecomeFirstResponder to YES

- (BOOL)canBecomeFirstResponder {
return YES;
}

4.set inputview as datepicker

self.inputView = self.datePicker;

5.set UIResponder to firstResponder when you want

[self becomeFirstResponder];

5.you can see datepicker slide in like keyboard

wlixcc
  • 1,132
  • 10
  • 14