Skip to content

Commit

Permalink
Done button for the keyboard
Browse files Browse the repository at this point in the history
  • Loading branch information
emretufekci committed Jun 9, 2021
1 parent e77c002 commit 0d4d41e
Showing 1 changed file with 39 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,15 @@ class ViewController: UIViewController {

//Listen incoming call via function pointer
CPPWrapper().incoming_call_wrapper(incoming_call_swift)


//Done button to the keyboard
sipIpTField.addDoneButtonOnKeyboard()
sipPortTField.addDoneButtonOnKeyboard()
sipUsernameTField.addDoneButtonOnKeyboard()
sipPasswordTField.addDoneButtonOnKeyboard()
}


//Refresh Button
@IBAction func refreshStatus(_ sender: UIButton) {
if (CPPWrapper().registerStateInfoWrapper()){
Expand Down Expand Up @@ -154,3 +160,35 @@ class ViewController: UIViewController {


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

0 comments on commit 0d4d41e

Please sign in to comment.