首页 > 代码库 > DatePicker使用

DatePicker使用

// 创建时间选择器    UIDatePicker *picker = [[UIDatePicker alloc] init];        // 设置时间格式为只显示日期    picker.datePickerMode = UIDatePickerModeDate;    // 显示中文    picker.locale = [[NSLocale alloc] initWithLocaleIdentifier:@"ZH-CN"];        // 设置键盘按为datePicker    self.inputField.inputView = picker;        // 创建工具条    UIToolbar *toolbar = [[UIToolbar alloc] initWithFrame:CGRectMake(0, 0, 320, 44)];        // 设置工具条背景色    toolbar.tintColor = [UIColor orangeColor];        // 创建UIbarButtonItem       UIBarButtonItem *item1 = [[UIBarButtonItem alloc] initWithTitle:@"上一个" style:UIBarButtonItemStylePlain target:self action:@selector(previousBtn)];    UIBarButtonItem *item2 = [[UIBarButtonItem alloc] initWithTitle:@"下一个" style:UIBarButtonItemStylePlain target:self action:@selector(previousBtn)];    UIBarButtonItem *item3 = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:self action:nil];    UIBarButtonItem *item4 = [[UIBarButtonItem alloc] initWithTitle:@"完成" style:UIBarButtonItemStylePlain target:self action:@selector(previousBtn)];        // 给工具条添加子控件    toolbar.items = @[item1,item2, item3,item4];        // 给文本框添加辅助视图    self.inputField.inputAccessoryView = toolbar;

效果图: