gpt4 book ai didi

swift - iOS 键盘只有数字和文本

转载 作者:行者123 更新时间:2023-11-28 09:06:11 25 4
gpt4 key购买 nike

我想要一个类似于这个的键盘: enter image description here

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

最佳答案

有一种简单的方法可以实现,您必须为其制作自定义键盘,因为没有您想要的内置键盘。所以下载这个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

关于swift - iOS 键盘只有数字和文本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30685309/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com