在datepicker调出的自定义键盘上设置toolbar

来源:互联网 发布:hammer.js 放大缩小 编辑:程序博客网 时间:2024/03/29 20:57
- (void)viewDidLoad {    [super viewDidLoad];    // Do any additional setup after loading the view, typically from a nib.        //自定义文本框的键盘    //self.inputField.inputView = [UIButton buttonWithType:UIButtonTypeContactAdd];    UIDatePicker *picker = [[UIDatePicker alloc]init];    picker.datePickerMode = UIDatePickerModeDate;    picker.locale = [[NSLocale alloc]initWithLocaleIdentifier:@"zh_CN"];        //这就是自定的文本框的键盘(不设置的话默认使用的是系统的键盘)    self.inputField.inputView = picker;    //self.inputField.inputAccessoryView = [UIButton buttonWithType:UIButtonTypeContactAdd];    UIToolbar *mytoolbar = [[UIToolbar alloc]init];    mytoolbar.frame =  CGRectMake(0, 0, 320, 44);    mytoolbar.barTintColor = [UIColor greenColor];    UIBarButtonItem *item1 = [[UIBarButtonItem alloc]initWithTitle:@"上一个" style:UIBarButtonItemStylePlain target:self action:@selector(previousClicked)];    item1.enabled = NO;//这是设置是否能用的    UIBarButtonItem *item2 = [[UIBarButtonItem alloc]initWithTitle:@"下一个" style:UIBarButtonItemStylePlain target:self action:@selector(nextClicked)];    UIBarButtonItem *item3 = [[UIBarButtonItem alloc]initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:nil action:nil];    UIBarButtonItem *item4 = [[UIBarButtonItem alloc]initWithTitle:@"确定" style:UIBarButtonItemStylePlain target:self action:@selector(doneClicked)];    mytoolbar.items = @[item1,item2,item3,item4];    self.inputField.inputAccessoryView = mytoolbar;}-(void)previousClicked{    NSLog(@"previous clicked");}-(void)nextClicked{    NSLog(@"next clicked");}-(void)doneClicked{    NSLog(@"done clicked");    [self.view endEditing:YES];//键盘退出}

0 0
原创粉丝点击