Created
July 12, 2017 04:51
-
-
Save truongngoclinh/accfc4855b54804ee110ca3c3910161b to your computer and use it in GitHub Desktop.
Show a UIDatePicker on bottom and attached with UITextField.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
UIDatePicker *datePicker = [[UIDatePicker alloc] init]; | |
datePicker.backgroundColor = [UIColor whiteColor]; | |
datePicker.datePickerMode = UIDatePickerModeDate; | |
[datePicker setMinimumDate:[self.dateFormatter dateFromString:@"1980-01-01"]]; | |
[datePicker setMaximumDate:[self.dateFormatter dateFromString:@"2050-01-01"]]; | |
[datePicker setLocale:[NSLocale localeWithLocaleIdentifier:[CPLanguage sharedInstance].currentLanguageCode]]; | |
self.dateFormatter = [[CPDateFormatter alloc] init]; | |
[self.dateFormatter setDateFormat:@"dd-MM-yyyy"]; | |
UIToolbar *toolBar = [[UIToolbar alloc] initWithFrame:CGRectMake(0, 0, self.scrollView.frame.size.width, 45)]; | |
CPBarButtonItem *btnDone = [[CPBarButtonItem alloc] initWithTitle:@"Done" style:UIBarButtonItemStyleBordered target:self action:@selector(showSelectedDate:)]; | |
[btnDone setTintColor:[UIColor blueColor]]; | |
[btnDone setObj:datePicker]; | |
CPBarButtonItem *space = [[CPBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:nil action:nil]; | |
[toolBar setTintColor:[UIColor grayColor]]; | |
[toolBar setItems:[NSArray arrayWithObjects:space, btnDone, nil]]; | |
[self.bankAccountValidFromTextField setInputView:datePicker]; | |
[self.bankAccountValidFromTextField setInputAccessoryView:toolBar]; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment