How to add done button on keyboard on top of keyboard in IOS?

前端 未结 8 1564
悲哀的现实
悲哀的现实 2020-12-08 04:04

I want to add the Done button on the top of keyboard on right side in iOS for a textView.Please tell me how can i do that?

I w

8条回答
  •  感情败类
    2020-12-08 04:56

    It can be done using storyboard:

    1. Add UITextField to UIViewController view.
    2. Add UIToolbar in the first level of UIViewController
    3. Add UIBarButtonItem into the UIToolbar.
    4. Connect UItoolbar to the code using IBOutlet.
    5. Connect UIBarButtonItem to the code using IBAction (as didClick).
    6. Make the UITextField will be delegating to UIViewController.
    7. In the didClick function end editing (view.endEditing(true))
    8. In the delegate function textFieldShouldBeginEditing should be: textField.inputAccessoryView = toolbar and returns true.

提交回复
热议问题