IOS DatePicker 和 UIBarButtonItem 常用属性
- (void)viewDidLoad { [super viewDidLoad]; // // self.inputTextField.inputView = [[UISwitch alloc ] init]; // 1.创建时间选择器 UIDatePicker *datePicker = [[UIDatePicker alloc] init]; // 设置只显示日期 datePicker.datePickerMode = UIDatePickerModeDate; // 设置日期为中文 datePicker.locale = [[NSLocale alloc] initWithLocaleIdentifier:@"zh_CN"]; self.inputTextField.inputView = datePicker; // 2.创建工具条 UIToolbar *toolbar = [[UIToolbar alloc] init]; toolbar.barTintColor = [UIColor purpleColor]; toolbar.frame = CGRectMake(0, 0, 320, 44); // 2.1给工具条添加按钮 UIBarButtonItem *item0 = [[UIBarButtonItem alloc] initWithTitle:@"上一个" style:UIBarButtonItemStylePlain target:self action:@selector(previousBtnClick)]; UIBarButtonItem *item3 = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:nil action:nil]; UIBarButtonItem *item1 = [[UIBarButtonItem alloc] initWithTitle:@"下一个" style:UIBarButtonItemStylePlain target:self action:@selector(previousBtnClick)]; UIBarButtonItem *item2 = [[UIBarButtonItem alloc] initWithTitle:@"完成" style:UIBarButtonItemStylePlain target:self action:@selector(previousBtnClick)]; toolbar.items = @[item0, item1, item3, item2]; // 设置文本输入框键盘的辅助视图 self.inputTextField.inputAccessoryView= toolbar; /* // 1.创建最外面的大view UIView *view = [[UIView alloc] init]; view.backgroundColor = [UIColor redColor]; view.frame = CGRectMake(0, 480 - 162 - 44, 320, 162 + 44); // 2.创建工具条 UIToolbar *toolbar = [[UIToolbar alloc] init]; toolbar.barTintColor = [UIColor purpleColor]; toolbar.frame = CGRectMake(0, 0, 320, 44); [view addSubview:toolbar]; // 2.1给工具条添加按钮 UIBarButtonItem *item0 = [[UIBarButtonItem alloc] initWithTitle:@"上一个" style:UIBarButtonItemStylePlain target:self action:@selector(previousBtnClick)]; UIBarButtonItem *item3 = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:nil action:nil]; UIBarButtonItem *item1 = [[UIBarButtonItem alloc] initWithTitle:@"下一个" style:UIBarButtonItemStylePlain target:self action:@selector(previousBtnClick)]; UIBarButtonItem *item2 = [[UIBarButtonItem alloc] initWithTitle:@"完成" style:UIBarButtonItemStylePlain target:self action:@selector(previousBtnClick)]; toolbar.items = @[item0, item1, item3, item2]; // 3.创建时间选择器 // 1.创建时间选择器 UIDatePicker *datePicker = [[UIDatePicker alloc] init]; // 设置只显示日期 datePicker.datePickerMode = UIDatePickerModeDate; // 设置日期为中文 datePicker.locale = [[NSLocale alloc] initWithLocaleIdentifier:@"zh_CN"]; datePicker.frame = CGRectMake(0, 44, 320, 162); [view addSubview:datePicker]; // 4.设置文本输入框的自定义键盘为大view self.inputTextField.inputView = view; */
}