date picker Unknown 06:26:00 Unknown datePicker = [[UIDatePicker alloc]init]; datePicker.datePickerMode = UIDatePickerModeDate; datePicker.backgroundColor=[UIColor whiteColor]; UIToolbar *toolbar = [[UIToolbar alloc] initWithFrame: CGRectMake(0, 0, 320, 44)]; toolbar.barStyle = UIBarStyleBlackOpaque; toolbar.autoresizingMask = UIViewAutoresizingFlexibleWidth; toolbar.backgroundColor=[UIColor colorWithRed:(63.0f/255.0f) green:(81.0f/255.0f) blue:(181.0f/255.0f) alpha:1]; UIBarButtonItem *doneButton = [[UIBarButtonItem alloc] initWithTitle: @"Done" style: UIBarButtonItemStyleDone target: self action: @selector(showSelectedDate)]; [doneButton setTintColor:[UIColor whiteColor]]; UIBarButtonItem* flexibleSpace = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:nil action:nil]; UIBarButtonItem *cancelButton = [[UIBarButtonItem alloc] initWithTitle: @"Cancel" style: UIBarButtonItemStyleDone target: self action: @selector(showcancelbtnclicked)]; [cancelButton setTintColor:[UIColor whiteColor]]; toolbar.items = [NSArray arrayWithObjects:doneButton,flexibleSpace,cancelButton,nil]; -(void)toSelectedDate { NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init]; dateFormatter.dateFormat = @"yyyy-MM-dd"; self.toDateTextField.text = [NSString stringWithFormat:@"%@",[dateFormatter stringFromDate:toDatePicker.date]]; endDate=self.toDateTextField.text; [self.toDateTextField resignFirstResponder]; } -(void)showcancelbtnclicked { //datepicker.hidden=YES; [self.fromDateTextField resignFirstResponder]; } [self.fromDateTextField setInputAccessoryView:toolbar]; self.fromDateTextField.inputView = datePicker; Tweet Share Share Share Share Sign up here with your email
datePicker.datePickerMode = UIDatePickerModeDate;
datePicker.backgroundColor=[UIColor whiteColor];
UIToolbar *toolbar = [[UIToolbar alloc] initWithFrame: CGRectMake(0, 0, 320, 44)];
toolbar.barStyle = UIBarStyleBlackOpaque;
toolbar.autoresizingMask = UIViewAutoresizingFlexibleWidth;
toolbar.backgroundColor=[UIColor colorWithRed:(63.0f/255.0f) green:(81.0f/255.0f) blue:(181.0f/255.0f) alpha:1];
UIBarButtonItem *doneButton = [[UIBarButtonItem alloc] initWithTitle: @"Done" style: UIBarButtonItemStyleDone target: self action: @selector(showSelectedDate)];
[doneButton setTintColor:[UIColor whiteColor]];
UIBarButtonItem* flexibleSpace = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:nil action:nil];
UIBarButtonItem *cancelButton = [[UIBarButtonItem alloc] initWithTitle: @"Cancel" style: UIBarButtonItemStyleDone target: self action: @selector(showcancelbtnclicked)];
[cancelButton setTintColor:[UIColor whiteColor]];
toolbar.items = [NSArray arrayWithObjects:doneButton,flexibleSpace,cancelButton,nil];
-(void)toSelectedDate
{
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
dateFormatter.dateFormat = @"yyyy-MM-dd";
self.toDateTextField.text = [NSString stringWithFormat:@"%@",[dateFormatter stringFromDate:toDatePicker.date]];
endDate=self.toDateTextField.text;
[self.toDateTextField resignFirstResponder];
}
-(void)showcancelbtnclicked
{
//datepicker.hidden=YES;
[self.fromDateTextField resignFirstResponder];
}
[self.fromDateTextField setInputAccessoryView:toolbar];
self.fromDateTextField.inputView = datePicker;