【发布时间】:2020-09-09 05:44:26
【问题描述】:
每次我点击 UItextview 这个剪贴板都会出现在底部,我怎样才能以编程方式禁用它?
【问题讨论】:
标签: ios swift uitextfield uitextview
每次我点击 UItextview 这个剪贴板都会出现在底部,我怎样才能以编程方式禁用它?
【问题讨论】:
标签: ios swift uitextfield uitextview
在 iPhone 上,您只需设置 autocorrectionType = .no 即可完全移除键盘上方的那个栏。
在 iPad 上,您应该首先添加这些扩展:
extension UITextView {
func hideSuggestions() {
// Removes suggestions only
autocorrectionType = .no
//Removes Undo, Redo, Copy & Paste options
removeUndoRedoOptions()
}
}
extension UITextField {
func hideSuggestions() {
// Removes suggestions only
autocorrectionType = .no
//Removes Undo, Redo, Copy & Paste options
removeUndoRedoOptions()
}
}
extension UIResponder {
func removeUndoRedoOptions() {
//Removes Undo, Redo, Copy & Paste options
inputAssistantItem.leadingBarButtonGroups = []
inputAssistantItem.trailingBarButtonGroups = []
}
}
【讨论】:
您可以禁用 textView 用户交互:
yourTextView.isUserInteractionEnabled = false
或者您可以禁用 textView 的可编辑性
yourTextView.isEditable = false
更新
如果您想让光标出现,但不希望此剪贴板出现,请将您的 textView 设置为第一响应者,并将您的 textView inputView 设置为空白 UIView():
textView.becomeFirstResponder()
之后将你的 textView inputView 设置为空白 UIView():
textView.inputView = UIView()
【讨论】: