How to move UIButton into a keypad when user start typing

176 Views Asked by At

I have a UIButton at bottom of the screen and when the user types in UITextView i want that button to get attached to the keypad like the screenshot I have attached. Please give some sample codes.

Designenter image description here

1

There are 1 best solutions below

5
Abdul Hoque Nuri On BEST ANSWER

As per your question, You just need to add your button to textfield inputAccessoryView.

yourTextField.inputAccessoryView = confirmButton

To handle your original Button position, Create temporary a Button same as your Original including method name.

  let tempButton = UIButton(frame: CGRect(x: 0, y: 0, width: view.frame.size.width, height: 30))
    tempButton.backgroundColor = UIColor.blue
    tempButton.setTitle("YourConfirmButton", for: .normal)
    tempButton.setTitleColor(UIColor.white, for: .normal)
    tempButton.addTarget(self, action: #selector(self.onTapConfirmButton), for: .touchUpInside)
    yourTextField.inputAccessoryView = tempButton