gpt4 book ai didi

ios - 为什么当我点击文本字段时工具栏不显示?

转载 作者:行者123 更新时间:2023-12-01 21:47:04 25 4
gpt4 key购买 nike

当点击文本字段时,我想在小键盘键盘上方实现一个完成的工具栏,但是由于某种原因工具栏没有显示。

使用了以下代码示例:

extension UITextField{

@IBInspectable var doneAccessory: Bool{
get{
return self.doneAccessory
}
set (hasDone) {
if hasDone{
addDoneButtonOnKeyboard()
}
}
}

func addDoneButtonOnKeyboard()
{
let doneToolbar: UIToolbar = UIToolbar(frame: CGRect.init(x: 0, y: 0, width: UIScreen.main.bounds.width, height: 50))
doneToolbar.barStyle = .default

let flexSpace = UIBarButtonItem(barButtonSystemItem: .flexibleSpace, target: nil, action: nil)
let done: UIBarButtonItem = UIBarButtonItem(title: "Done", style: .done, target: self, action: #selector(self.doneButtonAction))

let items = [flexSpace, done]
doneToolbar.items = items
doneToolbar.sizeToFit()

self.inputAccessoryView = doneToolbar
}

@objc func doneButtonAction()
{
self.resignFirstResponder()
}
}

最佳答案

确保在你的 Storyboard中,TextField的属性(property)检查员doneAccessory属性设置为 ON
enter image description here

和 O/P 看起来像

enter image description here

关于ios - 为什么当我点击文本字段时工具栏不显示?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62106747/

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