Home > OS >  How to move UIButton into a keypad when user start typing
How to move UIButton into a keypad when user start typing

Time:09-25

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

CodePudding user response:

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
  • Related