[英]Specific keyboard button pressed in Swift
每当按下键盘上的特定按钮时,是否可以调用函数?
如:
if (textField.spaceIsClicked){
checkWords();
}
您可以通过以下方式使用UITextFieldDelegate
委托函数shouldChangeCharactersInRange
:
import UIKit
class ViewController: UIViewController, UITextFieldDelegate {
@IBOutlet weak var textF: UITextField!
override func viewDidLoad() {
super.viewDidLoad()
textF.delegate = self
}
func textField(textField: UITextField, shouldChangeCharactersInRange range: NSRange, replacementString string: String) -> Bool {
if string == " " {
//Run your function here
println("SpaceBar is pressed")
}
return true
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.