Swift提供了12种键盘类型:
在开发中,我们可以根据不同的需求,选择不同的键盘样式,例如,当我们只需要输入手机号码时,可以选择纯数字类型的键盘(.NumbersAndPunctuation),当我们需要输入网址时,可以选择URL样式的键盘(.URL),其中,默认的键盘样式(.Default)
我们可以通过输入框的 UIKeyboardType 来设置键盘样式
nameView.textFeild.keyboardType = .numberPad
下面图像将一一展示个个类型的区别
default
![](https://img.haomeiwen.com/i3489374/900a720a40851515.png)
numbersAndPunctuation
![](https://img.haomeiwen.com/i3489374/d53b67fd5b422dc4.png)
url
![](https://img.haomeiwen.com/i3489374/76fb5613a896ca4b.png)
numberPad,asciiCapableNumberPad
![](https://img.haomeiwen.com/i3489374/14f042d7cbbe1afb.png)
phonePad
![](https://img.haomeiwen.com/i3489374/f3aa87637e4b5eb1.png)
emailAddress
![](https://img.haomeiwen.com/i3489374/a42b5d1ad95c6317.png)
decimalPad
![](https://img.haomeiwen.com/i3489374/72825a11a51158b5.png)
![](https://img.haomeiwen.com/i3489374/b6a709de7bd522fc.png)
webSearch
![](https://img.haomeiwen.com/i3489374/af29993da46b8bee.png)
2.取消键盘,如下
UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(closeKey)];
[self.tableV addGestureRecognizer:tap];
-(void)closeKey{
[self.tableV endEditing:YES];
}
添加这几行代码即可,tableV是转换成自己的UITableView即可
网友评论