How can I show a UIDatePicker instead of a keyboard when a user selects a UITextField?

后端 未结 4 1970
忘了有多久
忘了有多久 2021-02-14 14:32

I have a nice clean UI within a table view which has a few text fields for the user to fill out. One of the fields is for the user\'s birthday.

I\'d like to have it so t

4条回答
  •  你的背包
    2021-02-14 15:23

    Old question but the correct way to do this these days would be to set the UITextField's inputView to a picker you created somewhere. Something like this:

    UIPickerView *myPicker = [[UIPickerView alloc] init];
    // set picker frame, options, etc...
    // N.B. origin for the picker's frame should be 0,0
    
    [myTextField setInputView:myPicker];
    

    When you go to edit a UITextField, iOS really just displays whatever view is at textField.inputView which by default is the keyboard, you can make it anything you want as long as it's a subclass of UIView.

提交回复
热议问题