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;

郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。