Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I make a modal date picker that only covers half the screen?

I want to have the same effect as the birthday date setter in the iPhone contacts app. How do I have a modal date picker come up only halfway on the screen.

I want the date picker to be over a UITableView (like in the iphone contacts app). I would like the UITableView to scroll freely behind the date picker (like in the iphone contacts app).

Thanks in advance.

like image 206
rustybeanstalk Avatar asked Dec 13 '11 03:12

rustybeanstalk


People also ask

How do I change the pop position in jQuery Datepicker control?

To change the position of the jQuery UI Datepicker just modify . ui-datepicker in the css file. The size of the Datepicker can also be changed in this way, just adjust the font size.


1 Answers

By far, the best way to achieve a date-picker/uipicker keyboard-like is to use the input view property of a textfield:

  1. Build a simple custom UITableViewCell that contains a UITextField (It's important only because the question was about embedding one in a table view)

    @interface pickerCell : UITableViewCell
    {
        UITextField *txtTextField;
        UIPickerView* dtpPicker;
    }
    
  2. set the TextField's inputview to be the UIPickerView (Make sure they have both been allocated and initialized first):

    txtTextField.inputView = dtpPicker;
    
  3. You are almost done. Now when the textfield becomes the first responder (the user tapped it), the user will be presented with a picker view. Just fill it with your own values. or use a date picker.

  4. You can set the picker's delegate/datasource to the same cell (if it will always be a birthdate cell) or have the cell's superview load it with data. Whichever choice you make, be sure to update the txtTextField.text on

    pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component
    

Good luck! Elad.

like image 170
eladleb Avatar answered Oct 20 '22 23:10

eladleb