首页 > 代码库 > IOS - DatePicker的使用
IOS - DatePicker的使用
UIDatePicker *picker = [[UIDatePicker alloc] init];
picker.datePickerMode = UIDatePickerModeDate;
picker.locale = [[NSLocale alloc] initWithLocaleIdentifier:@"zh_CN"];
// 设置键盘
self.myfield.inputView = picker;
// 设置键盘上面的工具条
self.myfield.inputAccessoryView = [UIButton buttonWithType:UIButtonTypeContactAdd];
// 设置键盘上的ToolBar
UIBarButtonItem *prevButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"上一项" style:UIBarButtonItemStyleBordered target:self action:@selector(ShowPrevious)];
UIBarButtonItem *nextButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"下一项" style:UIBarButtonItemStyleBordered target:self action:@selector(ShowNext)];
UIBarButtonItem *hiddenButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"隐藏键盘" style:UIBarButtonItemStyleBordered target:self action:@selector(HiddenKeyBoard)];
UIBarButtonItem *spaceButtonItem = [[UIBarButtonItem alloc]initWithBarButtonSystemItem: UIBarButtonSystemItemFlexibleSpace target:nil action:nil];
UIToolbar *accessoryView = [[UIToolbar alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, 44)];
accessoryView.barStyle = UIBarStyleBlackTranslucent;
accessoryView.items = [NSArray arrayWithObjects:prevButtonItem,nextButtonItem,spaceButtonItem,hiddenButtonItem,nil];
self.myfield.inputAccessoryView = accessoryView;
IOS - DatePicker的使用