gpt4 book ai didi

ios - 如何使用 Swift 将 "Done"按钮添加到 iOS 中的小键盘?

转载 作者:行者123 更新时间:2023-11-29 05:50:00 26 4
gpt4 key购买 nike

它在默认键盘上工作正常,但我无法让它在数字键盘上工作。

有什么想法吗?

最佳答案

据我所知,键盘部分无法添加“完成”按钮;您需要将 inputAccessoryView 添加到 UITextFieldUITextView (如果您正在使用的话)。

检查 documentation for more info .

编辑:检查this question for an example关于如何做到这一点。

编辑 2:类似 example in Swift .

编辑 3:编辑 2 中的代码,因为链接可能会过期。

override func viewDidLoad()
{
super.viewDidLoad()

//--- add UIToolBar on keyboard and Done button on UIToolBar ---//
self.addDoneButtonOnKeyboard()
}

//--- *** ---//

func addDoneButtonOnKeyboard()
{
var doneToolbar: UIToolbar = UIToolbar(frame: CGRectMake(0, 0, 320, 50))
doneToolbar.barStyle = UIBarStyle.BlackTranslucent

var flexSpace = UIBarButtonItem(barButtonSystemItem: UIBarButtonSystemItem.FlexibleSpace, target: nil, action: nil)
var done: UIBarButtonItem = UIBarButtonItem(title: "Done", style: UIBarButtonItemStyle.Done, target: self, action: Selector("doneButtonAction"))

var items = NSMutableArray()
items.addObject(flexSpace)
items.addObject(done)

doneToolbar.items = items
doneToolbar.sizeToFit()

self.textView.inputAccessoryView = doneToolbar
self.textField.inputAccessoryView = doneToolbar

}

func doneButtonAction()
{
self.textViewDescription.resignFirstResponder()
}

swift 4.2

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()

txtMobileNumber.inputAccessoryView = doneToolbar
}

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

关于ios - 如何使用 Swift 将 "Done"按钮添加到 iOS 中的小键盘?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55765942/

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