1 - (void)viewDidLoad 2 { 3 [super viewDidLoad]; 4 // 5 // self.inputTextField.inputView = [[UISwitch alloc ] init]; 6 7 // 1.创建时间选择器 8 UIDatePicker *datePicker = [[UIDatePicker alloc] init]; 9 // 设置只显示日期 10 datePicker.datePickerMode = UIDatePickerModeDate; 11 // 设置日期为中文 12 datePicker.locale = [[NSLocale alloc] initWithLocaleIdentifier:@"zh_CN"]; 13 14 self.inputTextField.inputView = datePicker; 15 } 16 17 18 @end 19 t:) forControlEvents:UIControlEventValueChanged]; 20 self.inputTextField.inputView = datePicker; 21 22 23 // 2.创建工具条 24 UIToolbar *toolbar = [[UIToolbar alloc] init]; 25 toolbar.barTintColor = [UIColor purpleColor]; 26 toolbar.frame = CGRectMake(0, 0, 320, 44); 27 28 // 2.1给工具条添加按钮 29 UIBarButtonItem *item0 = [[UIBarButtonItem alloc] initWithTitle:@"上一个" style:UIBarButtonItemStylePlain target:self action:@selector(previousBtnClick)]; 30 31 UIBarButtonItem *item3 = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:nil action:nil]; 32 33 UIBarButtonItem *item1 = [[UIBarButtonItem alloc] initWithTitle:@"下一个" style:UIBarButtonItemStylePlain target:self action:@selector(previousBtnClick)]; 34 UIBarButtonItem *item2 = [[UIBarButtonItem alloc] initWithTitle:@"完成" style:UIBarButtonItemStylePlain target:self action:@selector(previousBtnClick)]; 35 toolbar.items = @[item0, item1, item3, item2]; 36 37 // 设置文本输入框键盘的辅助视图 38 self.inputTextField.inputAccessoryView= toolbar; 39 40 41 /* 42 // 1.创建最外面的大view 43 UIView *view = [[UIView alloc] init]; 44 view.backgroundColor = [UIColor redColor]; 45 view.frame = CGRectMake(0, 480 - 162 - 44, 320, 162 + 44); 46 47 // 2.创建工具条 48 UIToolbar *toolbar = [[UIToolbar alloc] init]; 49 toolbar.barTintColor = [UIColor purpleColor]; 50 toolbar.frame = CGRectMake(0, 0, 320, 44); 51 [view addSubview:toolbar]; 52 53 // 2.1给工具条添加按钮 54 UIBarButtonItem *item0 = [[UIBarButtonItem alloc] initWithTitle:@"上一个" style:UIBarButtonItemStylePlain target:self action:@selector(previousBtnClick)]; 55 56 UIBarButtonItem *item3 = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:nil action:nil]; 57 58 UIBarButtonItem *item1 = [[UIBarButtonItem alloc] initWithTitle:@"下一个" style:UIBarButtonItemStylePlain target:self action:@selector(previousBtnClick)]; 59 UIBarButtonItem *item2 = [[UIBarButtonItem alloc] initWithTitle:@"完成" style:UIBarButtonItemStylePlain target:self action:@selector(previousBtnClick)]; 60 toolbar.items = @[item0, item1, item3, item2]; 61 62 // 3.创建时间选择器 63 // 1.创建时间选择器 64 UIDatePicker *datePicker = [[UIDatePicker alloc] init]; 65 // 设置只显示日期 66 datePicker.datePickerMode = UIDatePickerModeDate; 67 // 设置日期为中文 68 datePicker.locale = [[NSLocale alloc] initWithLocaleIdentifier:@"zh_CN"]; 69 datePicker.frame = CGRectMake(0, 44, 320, 162); 70 [view addSubview:datePicker]; 71 72 // 4.设置文本输入框的自定义键盘为大view 73 self.inputTextField.inputView = view; 74 */ 75 76 } 77 78 - (void)previousBtnClick 79 { 80 NSLog(@"上一个"); 81 } 82 83 -(void)test:(UIDatePicker *)picker 84 { 85 NSLog(@"%@", picker); 86 } 87 @end