I need to add a "done" button to my date picker like in this image:
This is my code:
-(IBAction)chooseDate:(id)sender{
self.datepicker= [[UIDatePicker alloc] initWithFrame:CGRectMake(0, 0, 320, 216)];
self.datepicker.datePickerMode = UIDatePickerModeDate;
datepicker.backgroundColor = Rgb2UIColor(52, 170, 220);
[self.btnDone
addTarget:self
action:@selector(SetDatePickerTime:)
forControlEvents:UIControlEventTouchDown];
[self.view addSubview:self.datepicker];
}
The reference image of your question is showing that the app is using UIToolbar and i will assume that when tapping on date text field the datepicker with done button appears.And for this in some.h file
in some.m file
Create a date picker, then add it as the input view of the field in question (
self.fieldInQuestion.inputView = datePicker
). Next, create aUIToolBar
(height 44) withUIBarButton
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.With Swift
create a UIView and add it to the main view. Add a UIDatePicker to the new UIView. Add two UIButtons to the UIView.
I DO!!!!
}