ios textfield输入结束键盘怎么设置

如题所述

首先输入完成后按键盘上的done关闭键盘 首先在Interface Builder中选择TextFields,然后在Text Field Attributes中找到Text Input Traits,选择Return Key为done。OK 定义方法
- (IBAction) textFieldDoneEditing:(id)sender; //按下Done键关闭键盘

实现方法

//按完Done键以后关闭键盘
- (IBAction) textFieldDoneEditing:(id)sender
{
[sender resignFirstResponder];
}

然后找到事件Did End On Exit,与textFieldDoneEditing关联,OK。 如果是数字键盘,没有done键怎么办呢,我们通过触摸背景关闭键盘 定义方法
- (IBAction) backgroundTap:(id)sender; //通过触摸背景关闭键盘

实现方法

//通过触摸背景关闭键盘
- (IBAction) backgroundTap:(id)sender
{
[nameFiled resignFirstResponder];
[numberField resignFirstResponder];
}

然后选择背景的Touch Down事件,关联 backgroundTap,OK

这种方法有一点需要注意的是要把UIView改成UIControl.
温馨提示:内容为网友见解,仅供参考
无其他回答
相似回答