UIDatePicker with “done” button

后端 未结 5 1304
闹比i
闹比i 2021-01-01 20:34

I need to add a \"done\" button to my date picker like in this image:

\"enter

5条回答
  •  孤街浪徒
    2021-01-01 21:33

    Create a date picker, then add it as the input view of the field in question (self.fieldInQuestion.inputView = datePicker). Next, create a UIToolBar (height 44) with UIBarButton Item on it with the title "Done", target of self, and a selector (ex. @selector(done)). Add this as the input accessory view of the same field you made the date picker an input view for (self.fieldInQuestion.inputAccessoryView = UIToolbarInstance). In the selector method (-(void)done in the example above), make sure you use [self.fieldInQuestion resignFirstResponder] and it will dismiss it.

提交回复
热议问题