如何在键盘上方添加按钮 [英] How to add buttons above keyboard

查看:154
本文介绍了如何在键盘上方添加按钮的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在Stack Exchange应用程序中像这样的键盘上方添加按钮?而当您长按UITextView中的文本时,如何添加选择"和全选"?

How to add button above the keyboard like this one in Stack Exchange app? And when you long press the text in UITextView How to add "Select" and "Select All"?

推荐答案

第一个问题,您可以将textFieldinputAccessoryView设置为自定义视图,这可以自定义键盘的标题.

The first question, you can set textField's inputAccessoryView to your custom view, this can customize the keyboard's header.

结果:

您可以按照以下方式进行操作;

You can do it like below;

首先,您应该实例化要添加到键盘上方的视图.

first, you should instance the view you want to add above the keyboard.

class ViewController : UIViewController {

@IBOutlet weak var textField: UITextField!
override func viewDidLoad() {
    super.viewDidLoad()

    textField.inputAccessoryView = Bundle.main.loadNibNamed("CustomAccessoryView", owner: self, options: nil)?.first as! UIView?

在您的CustomAccessoryView中,您可以设置按钮的操作:

In your CustomAccessoryView, you can set the action of the button:

import UIKit

class CustomAccessoryView: UIView {

    @IBAction func clickLoveButton(_ sender: UIButton) {

        print("Love button clicked")
    }
}

这篇关于如何在键盘上方添加按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆