InputAccessoryView的子视图工具栏按钮不起作用

问题描述 投票:1回答:1

我尝试向Inputaccessoryview添加两个不同的工具栏。但是InputAccessoryView的子视图工具栏按钮不起作用。

我试图创建2个单独的uitoolbar并添加其中一个作为inputaccessoryview。然后我添加了第二个工具栏作为子视图。它看起来很好,但按钮不工作,它只是在那里看。

有我的代码

        let entryToolbar = UIToolbar(frame:CGRect(x: 0, y: -50, width: UIScreen.main.bounds.width, height: 50))
        entryToolbar.barStyle = Theme.barStyle!
        entryToolbar.tintColor = Theme.userColor
        let sendToolbar = UIToolbar(frame:CGRect(x: 0, y: -0, width: UIScreen.main.bounds.width, height: 50))
        sendToolbar.barStyle = Theme.barStyle!
        sendToolbar.tintColor = Theme.userColor

        sendToolbar.items = [
            UIBarButtonItem(title: "gönder", style: .plain, target: self, action: #selector(gonder)),
            UIBarButtonItem(barButtonSystemItem: .flexibleSpace, target: self, action: nil),
            UIBarButtonItem(title: "vazgeç", style: .plain, target: self, action: #selector(vazgec))]
        entryToolbar.items = [
            UIBarButtonItem(title: "(bkz:)", style: .plain, target: self, action: #selector(bkz)),
            UIBarButtonItem(title: "hede", style: .plain, target: self, action: #selector(hede)),
            UIBarButtonItem(barButtonSystemItem: .flexibleSpace, target: self, action: nil),
            UIBarButtonItem(title: "*", style: .plain, target: self, action: #selector(gizlihede)),
            UIBarButtonItem(barButtonSystemItem: .flexibleSpace, target: self, action: nil),
            UIBarButtonItem(title: "-spoiler-", style: .plain, target: self, action: #selector(spoiler)),
            UIBarButtonItem(title: "http://", style: .plain, target: self, action: #selector(link))]
        sendToolbar.sizeToFit()
        sendToolbar.addSubview(entryToolbar)
        entryGir.inputAccessoryView = sendToolbar

如何添加多工具栏作为inputaccessoryview,它如何工作这个按钮?

有一个viewcontroller的视图。 https://i.imgur.com/0Uqo9fL.png

ios swift toolbar inputaccessoryview
1个回答
0
投票

您无法将任何子视图添加到UIToolbar。要使工具栏与提供的图像一样,您需要做的是:创建扩展UIView的自定义类,通过代码配置自定义UIView UI或从NIB加载它,并在该自定义类中编写按钮和其他UI元素的所有控制逻辑实现。然后使用自定义UIView作为你的inputAccessoryView


You can get some more information of where to begin with custom inputAccessoryView implementation here.
© www.soinside.com 2019 - 2024. All rights reserved.