gpt4 book ai didi

ios - 带有用于关闭键盘垫的 uibar 的文本字段

转载 作者:行者123 更新时间:2023-11-30 11:10:35 25 4
gpt4 key购买 nike

我创建了一个申请表,在某些字段中我使用数字键盘。由于缺少关闭按钮,我进入了包含关闭按钮的 uibar。

我目前为每个字段创建一个 uibar,因为我必须指定目标。是否可以只创建一个具有多个目标的 uibar?

@IBOutlet weak var TXTNome: UITextField!
@IBOutlet weak var TXTAltezza: UITextField!
@IBOutlet weak var TXTPeso: UITextField!
@IBOutlet weak var TXTEta: UITextField!

// Altezza
let keyboardToolbar = UIToolbar(frame: CGRect(x: 0, y: 0,
width: self.view.bounds.size.width,
height: 44))
keyboardToolbar.barStyle = UIBarStyle.blackTranslucent
keyboardToolbar.backgroundColor = UIColor.red
keyboardToolbar.tintColor = UIColor.white

let flex = UIBarButtonItem(barButtonSystemItem: .flexibleSpace, target: nil, action: nil)
let save = UIBarButtonItem(title: "Chiudi",
style: .done,
target: TXTAltezza,
action: #selector(resignFirstResponder))
keyboardToolbar.setItems([flex, save], animated: false)
TXTAltezza.inputAccessoryView = keyboardToolbar

// Peso
let keyboardToolbar2 = UIToolbar(frame: CGRect(x: 0, y: 0,
width: self.view.bounds.size.width,
height: 44))
keyboardToolbar2.barStyle = UIBarStyle.blackTranslucent
keyboardToolbar2.backgroundColor = UIColor.red
keyboardToolbar2.tintColor = UIColor.white

let flex2 = UIBarButtonItem(barButtonSystemItem: .flexibleSpace, target: nil, action: nil)
let save2 = UIBarButtonItem(title: "Chiudi",
style: .done,
target: TXTPeso,
action: #selector(resignFirstResponder))
keyboardToolbar2.setItems([flex2, save2], animated: false)
TXTPeso.inputAccessoryView = keyboardToolbar2

等等等等

image

最佳答案

        let toolBar = UIToolbar()
toolBar.barStyle = UIBarStyle.default
toolBar.isTranslucent = true
toolBar.sizeToFit()
let doneButton = UIBarButtonItem(title: "Done", style: UIBarButtonItemStyle.plain, target: self, action: #selector(doneClickOk))
toolBar.setItems([doneButton], animated: false)
toolBar.isUserInteractionEnabled = true
yourTextField.inputAccessoryView = toolBar
yourOthersTextfields.inputAccessoryView = toolBar


**Than call selector method**

@objc func doneClickOk(){
view.endEditing(true)
}

关于ios - 带有用于关闭键盘垫的 uibar 的文本字段,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52218955/

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