美文网首页
iOS在键盘上添加完成按钮

iOS在键盘上添加完成按钮

作者: wodeph | 来源:发表于2023-02-21 09:51 被阅读0次

[self.nameTextFieldaddTarget:selfaction:@selector(textField1TextDidBeginChange:)forControlEvents:UIControlEventEditingDidBegin];

- (void)textField1TextDidBeginChange:(UITextField*)nameFeild  {

    UIToolbar*toolBar =[UIToolbarnew];

    UIBarButtonItem *flexSpace = [[UIBarButtonItem alloc]initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:nil action:nil];

    UIBarButtonItem*doneBtn = [[UIBarButtonItemalloc]initWithTitle:@"完成" style:UIBarButtonItemStyleDonetarget:selfaction:@selector(numberFieldCancle)];

    doneBtn.tintColor=[UIColorblueColor];

    NSArray*items =@[flexSpace,doneBtn];

    toolBar.items= items;

    [toolBarsizeToFit];

    nameFeild.inputAccessoryView= toolBar;

}

 //收起键盘

- (void)numberFieldCancle{

[self.view resignFirstResponder]; 

[self.view endEditing:YES];

}

相关文章

网友评论

      本文标题:iOS在键盘上添加完成按钮

      本文链接:https://www.haomeiwen.com/subject/hgpnkdtx.html