ios 键盘追加完成按钮

//键盘追加完成按钮
UIToolbar * topView = [[UIToolbar alloc]initWithFrame:CGRectMake(0, 0, 320, 30)];
[topView setBarStyle:UIBarStyleDefault];
UIBarButtonItem * btnSpace = [[UIBarButtonItem alloc]initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:self action:nil];
UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
btn.frame = CGRectMake(2, 10, 50, 25);
[btn addTarget:self action:@selector(dismissKeyBoard) forControlEvents:UIControlEventTouchUpInside];
[btn setTitle:@"完成"forState:UIControlStateNormal];

[btn setTitleColor:[UIColor colorWithRed:31.0/255.0 green:112.0/255.0 blue:175.0/255.0 alpha:1.0] forState:UIControlStateNormal];

btn.titleLabel.textColor=[UIColor redColor];
UIBarButtonItem *doneBtn = [[UIBarButtonItem alloc]initWithCustomView:btn];
NSArray * buttonsArray = [NSArray arrayWithObjects:btnSpace,doneBtn,nil];
[topView setItems:buttonsArray];
[_texTest setInputAccessoryView:topView];
}

posted @ 2017-09-19 16:48  懒猫口米  阅读(416)  评论(0编辑  收藏  举报