键盘类型类型和代码


简介

键盘类型的书写风格和类型我想在这里总结一下。

定义

我通过跳转到定义检查了UIKeyboardType的定义(按住Command键并单击要检查的位置)。
如下。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
public enum UIKeyboardType : Int {


    case `default` = 0 // Default type for the current input method.

    case asciiCapable = 1 // Displays a keyboard which can enter ASCII characters

    case numbersAndPunctuation = 2 // Numbers and assorted punctuation.

    case URL = 3 // A type optimized for URL entry (shows . / .com prominently).

    case numberPad = 4 // A number pad with locale-appropriate digits (0-9, ?-?, ?-?, etc.). Suitable for PIN entry.

    case phonePad = 5 // A phone pad (1-9, *, 0, #, with letters under the numbers).

    case namePhonePad = 6 // A type optimized for entering a person's name or phone number.

    case emailAddress = 7 // A type optimized for multiple email address entry (shows space @ . prominently).

    @available(iOS 4.1, *)
    case decimalPad = 8 // A number pad with a decimal point.

    @available(iOS 5.0, *)
    case twitter = 9 // A type optimized for twitter text entry (easy access to @ #)

    @available(iOS 7.0, *)
    case webSearch = 10 // A default keyboard type with URL-oriented addition (shows space . prominently).

    @available(iOS 10.0, *)
    case asciiCapableNumberPad = 11 // A number pad (0-9) that will always be ASCII digits.


    public static var alphabet: UIKeyboardType { get } // Deprecated
}

似乎总共有13种类型。

  • 默认
  • 有能力
  • 数字和标点
  • 网址
  • 数位板
  • 手机板
  • 名称PhonePad
  • 电子邮件地址
  • 十进制垫
  • 推特
  • 网络搜索
  • asciiCapableNumberPad
  • 字母

实现方法

TextField连接到outlets,并使用viewDidLoad编写显示代码。
让我们更改以下内容以查看每种键盘类型。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
import UIKit

class ViewController: UIViewController {

    @IBOutlet var textField1: UITextField!
    @IBOutlet var textField2: UITextField!
    @IBOutlet var textField3: UITextField!
    @IBOutlet var textField4: UITextField!
    @IBOutlet var textField5: UITextField!
    @IBOutlet var textField6: UITextField!
    @IBOutlet var textField7: UITextField!
    @IBOutlet var textField8: UITextField!
    @IBOutlet var textField9: UITextField!
    @IBOutlet var textField10: UITextField!
    @IBOutlet var textField11: UITextField!
    @IBOutlet var textField12: UITextField!
    @IBOutlet var textField13: UITextField!

    override func viewDidLoad() {
        super.viewDidLoad()
        // Do any additional setup after loading the view.
        self.textField1.keyboardType = .default
        self.textField2.keyboardType = .asciiCapable
        self.textField3.keyboardType = .numbersAndPunctuation
        self.textField4.keyboardType = .URL
        self.textField5.keyboardType = .numberPad
        self.textField6.keyboardType = .phonePad
        self.textField7.keyboardType = .namePhonePad
        self.textField8.keyboardType = .emailAddress
        self.textField9.keyboardType = .decimalPad
        self.textField10.keyboardType = .twitter
        self.textField11.keyboardType = .webSearch
        self.textField12.keyboardType = .asciiCapableNumberPad
        self.textField13.keyboardType = .alphabet
    }
}

实施结果

①默认
スクリーンショット 2020-11-21 17.33.32.png

②asciiCapable
スクリーンショット 2020-11-21 17.32.19.png

③数字和标点符号
スクリーンショット 2020-11-21 17.35.22.png

④URL
スクリーンショット 2020-11-21 17.40.37.png

⑤numberPad
スクリーンショット 2020-11-21 17.41.29.png

⑥phonePad
スクリーンショット 2020-11-21 17.42.23.png

⑦namePhonePad
スクリーンショット 2020-11-21 17.42.57.png

⑧emailAddress
スクリーンショット 2020-11-21 17.43.44.png

⑨decimalPad
スクリーンショット 2020-11-21 17.44.26.png

⑩twitter
スクリーンショット 2020-11-21 17.45.00.png

?WebSearch
スクリーンショット 2020-11-21 17.45.42.png

?AsciiCapableNumberPad
スクリーンショット 2020-11-21 17.46.24.png

?字母
スクリーンショット 2020-11-21 17.47.00.png

终于

我不知道有13种类型。
我希望能够根据情况使用它!