UITextField在弹出的键盘上方,加一个带有完成按钮的toolBar工具栏

来源:互联网 发布:淘宝实木床 编辑:程序博客网 时间:2024/04/29 19:22



- (void)setTextFieldInputAccessoryView{    UIToolbar * topView = [[UIToolbar alloc]initWithFrame:CGRectMake(0, 0, WIDTH, 30)];    [topView setBarStyle:UIBarStyleDefault];    UIBarButtonItem * spaceBtn = [[UIBarButtonItem alloc]initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:self action:nil];    UIButton *doneBtn = [UIButton buttonWithType:UIButtonTypeSystem];    [doneBtn setTitle:@"完成" forState:UIControlStateNormal];    doneBtn.frame = CGRectMake(2, 5, 40, 25);    [doneBtn addTarget:self action:@selector(dealKeyboardHide) forControlEvents:UIControlEventTouchUpInside];    UIBarButtonItem *doneBtnItem = [[UIBarButtonItem alloc]initWithCustomView:doneBtn];    NSArray * buttonsArray = [NSArray arrayWithObjects:spaceBtn,doneBtnItem,nil];    [topView setItems:buttonsArray];    [self setInputAccessoryView:topView];    [self setAutocorrectionType:UITextAutocorrectionTypeNo];    [self setAutocapitalizationType:UITextAutocapitalizationTypeNone];}- (void)dealKeyboardHide {    [[[UIApplication sharedApplication] keyWindow] endEditing:YES];}


0 0
原创粉丝点击