我有一个UILabel子类,符合UIKeyInputs协议。但是当显示键盘时,预测视图位于键盘键下:这是屏幕截图:
以下是实施:
class CustomLabel: UILabel {
// some implementation, nothing important to effect keyboard.
}
extension CustomLabel: UIKeyInput {
var hasText: Bool {
if let text = self.text {
return text.isEmpty
}
return false
}
func insertText(_ text: String) {
self.text?.append(text)
}
func deleteBackward() {
guard let text = self.text else { return }
self.text = String(text.dropLast())
}
override var canBecomeFirstResponder: Bool {
return true
}
private var autocapitalizationType: UITextAutocapitalizationType {
return .none
}
private var autocorrectionType: UITextAutocorrectionType {
return .no
}
private var spellCheckingType: UITextSpellCheckingType {
return .no
}
private var keyboardType: UIKeyboardType {
return .twitter
}
private var returnKeyType: UIReturnKeyType {
return .done
}
private var keyboardAppearance: UIKeyboardAppearance {
return .default
}
}
我不明白的一件事是没有调用autocapitalizationType,autocorrectionType和键盘外观的其他协议方法。
我希望有人可以提供帮助。谢谢。
答案 0 :(得分:0)
UITextInputTraits
,您必须使用@objc var keyboardType: UIKeyboardType = .default
@objc var autocorrectionType: UITextAutocorrectionType = .no
作为
@objc var keyboardAppearance: UIKeyboardAppearance {
get { return .dark }
set(value) {}
}
或
td