Bryan C
Bryan C

Reputation: 1594

Anyone know how to slide in a UIDatePicker like keyboard?

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

Upvotes: 0

Views: 2004

Answers (2)

wlixcc
wlixcc

Reputation: 1492

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

Upvotes: 0

PeyloW
PeyloW

Reputation: 36752

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];
}

Upvotes: 1

Related Questions