如何添加“完成”使用Swift在IOS 8中按键到Numpad? [英] How to add "Done" button to Numpad in IOS 8 using Swift?
本文介绍了如何添加“完成”使用Swift在IOS 8中按键到Numpad?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
使用默认键盘工作正常,但我无法使用小键盘。
It works fine with the default keyboard, but I cant get it working with the numpad.
有什么想法吗?
推荐答案
据我所知,你不能在键盘部分添加完成按钮;你已经将 inputAccessoryView
添加到 UITextField
或 UITextView
(如果那就是你正在使用的那个)。
As far as I know, you can't add the Done button on the keyboard part; you'd have add a inputAccessoryView
to the UITextField
or UITextView
(if that's what you're using).
检查文档了解更多信息。
编辑 :请查看此问题以获取有关如何执行此操作的示例。
编辑2 :类似 Swift中的示例。
编辑3 :来自编辑的代码2,因为链接可能会过期。
Edit 3: Code from edit 2, as link may expire.
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()
self.textViewDescription.resignFirstResponder()
}
这篇关于如何添加“完成”使用Swift在IOS 8中按键到Numpad?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文