iOS键盘仅带数字和文字

时间:2015-06-06 16:52:55

标签: swift ios8

我想要一个与此类似的键盘: enter image description here

所以,只是第一行的数字和下面的字母..在iOS 8中有一个简单的方法吗? UIKeyboardType似乎都没有这种结构。

2 个答案:

答案 0 :(得分:0)

只需进入界面构建器并选择文本字段(或需要键盘的对象),然后选择文本字段下的属性检查器(如果是文本字段)。您可以找到键盘类型并选择所需内容(例如:数字键盘,小数点,数字和标点符号)。

答案 1 :(得分:0)

有一种简单的方法可以实现,因为没有内置的键盘可供选择。所以下载这个tasty-imitation-keyboard。您可以将其代码修改为DefaultKeyboard.swift,如下所示:

func defaultKeyboard() -> Keyboard {
    var defaultKeyboard = Keyboard()

    // add this row at index 0.
    for key in ["1", "2", "3", "4", "5", "6", "7", "8", "9", "0"] {
        var keyModel = Key(.Character)
        keyModel.setLetter(key)
        defaultKeyboard.addKey(keyModel, row: 0, page: 0)
    }

    for key in ["Q", "W", "E", "R", "T", "Y", "U", "I", "O", "P"] {
        var keyModel = Key(.Character)
        keyModel.setLetter(key)
        defaultKeyboard.addKey(keyModel, row: 1, page: 0)
    }

    for key in ["A", "S", "D", "F", "G", "H", "J", "K", "L"] {
        var keyModel = Key(.Character)
        keyModel.setLetter(key)
        defaultKeyboard.addKey(keyModel, row: 2, page: 0)
    }

    var keyModel = Key(.Shift)
    defaultKeyboard.addKey(keyModel, row: 3, page: 0)

    for key in ["Z", "X", "C", "V", "B", "N", "M"] {
        var keyModel = Key(.Character)
        keyModel.setLetter(key)
        defaultKeyboard.addKey(keyModel, row: 3, page: 0)
    }

    var backspace = Key(.Backspace)
    defaultKeyboard.addKey(backspace, row: 3, page: 0)

    var keyModeChangeNumbers = Key(.ModeChange)
    keyModeChangeNumbers.uppercaseKeyCap = "123"
    keyModeChangeNumbers.toMode = 1
    defaultKeyboard.addKey(keyModeChangeNumbers, row: 4, page: 0)

    var keyboardChange = Key(.KeyboardChange)
    defaultKeyboard.addKey(keyboardChange, row: 4, page: 0)

    var settings = Key(.Settings)
    defaultKeyboard.addKey(settings, row: 4, page: 0)

    var space = Key(.Space)
    space.uppercaseKeyCap = "space"
    space.uppercaseOutput = " "
    space.lowercaseOutput = " "
    defaultKeyboard.addKey(space, row: 4, page: 0)

    var returnKey = Key(.Return)
    returnKey.uppercaseKeyCap = "return"
    returnKey.uppercaseOutput = "\n"
    returnKey.lowercaseOutput = "\n"
    defaultKeyboard.addKey(returnKey, row: 4, page: 0)

    for key in ["1", "2", "3", "4", "5", "6", "7", "8", "9", "0"] {
        var keyModel = Key(.SpecialCharacter)
        keyModel.setLetter(key)
        defaultKeyboard.addKey(keyModel, row: 0, page: 1)
    }

    for key in ["-", "/", ":", ";", "(", ")", "$", "&", "@", "\""] {
        var keyModel = Key(.SpecialCharacter)
        keyModel.setLetter(key)
        defaultKeyboard.addKey(keyModel, row: 1, page: 1)
    }

    var keyModeChangeSpecialCharacters = Key(.ModeChange)
    keyModeChangeSpecialCharacters.uppercaseKeyCap = "#+="
    keyModeChangeSpecialCharacters.toMode = 2
    defaultKeyboard.addKey(keyModeChangeSpecialCharacters, row: 2, page: 1)

    for key in [".", ",", "?", "!", "'"] {
        var keyModel = Key(.SpecialCharacter)
        keyModel.setLetter(key)
        defaultKeyboard.addKey(keyModel, row: 2, page: 1)
    }

    defaultKeyboard.addKey(Key(backspace), row: 2, page: 1)

    var keyModeChangeLetters = Key(.ModeChange)
    keyModeChangeLetters.uppercaseKeyCap = "ABC"
    keyModeChangeLetters.toMode = 0
    defaultKeyboard.addKey(keyModeChangeLetters, row: 3, page: 1)

    defaultKeyboard.addKey(Key(keyboardChange), row: 3, page: 1)

    defaultKeyboard.addKey(Key(settings), row: 3, page: 1)

    defaultKeyboard.addKey(Key(space), row: 3, page: 1)

    defaultKeyboard.addKey(Key(returnKey), row: 3, page: 1)

    for key in ["[", "]", "{", "}", "#", "%", "^", "*", "+", "="] {
        var keyModel = Key(.SpecialCharacter)
        keyModel.setLetter(key)
        defaultKeyboard.addKey(keyModel, row: 0, page: 2)
    }

    for key in ["_", "\\", "|", "~", "<", ">", "€", "£", "¥", "•"] {
        var keyModel = Key(.SpecialCharacter)
        keyModel.setLetter(key)
        defaultKeyboard.addKey(keyModel, row: 1, page: 2)
    }

    defaultKeyboard.addKey(Key(keyModeChangeNumbers), row: 2, page: 2)

    for key in [".", ",", "?", "!", "'"] {
        var keyModel = Key(.SpecialCharacter)
        keyModel.setLetter(key)
        defaultKeyboard.addKey(keyModel, row: 2, page: 2)
    }

    defaultKeyboard.addKey(Key(backspace), row: 2, page: 2)

    defaultKeyboard.addKey(Key(keyModeChangeLetters), row: 3, page: 2)

    defaultKeyboard.addKey(Key(keyboardChange), row: 3, page: 2)

    defaultKeyboard.addKey(Key(settings), row: 3, page: 2)

    defaultKeyboard.addKey(Key(space), row: 3, page: 2)

    defaultKeyboard.addKey(Key(returnKey), row: 3, page: 2)

    return defaultKeyboard
}

你的结果将是:

enter image description here