2

我试图让我的 Inputview 的背景透明,但我只把它变成灰色。

在此处输入图像描述

代码是:

    let fakeField : UITextField = UITextField(frame: CGRect.zero)
    //1
    InputViewCollection = InputView(frame: CGRect(x: 0, y: 0, width: 0, height: 216)) //Intialize custom input view
    InputViewCollection?.delegate = self //delegate
    InputViewCollection?.dataSource = self //datasource

    //2
    InputViewCollection?.backgroundColor = UIColor.clear
    self.fakeField.inputView = InputViewCollection //Assign input view
    self.fakeField.keyboardAppearance = .default
    self.view.addSubview(self.fakeField)

如何保留 inputview 的透明背景?

谢谢

4

3 回答 3

7

使用时inputView,必须使用标准键盘的宽度。但是,您可以将空视图设置为inputView,并将自定义键盘设置为inputAccessoryView。这没有灰色背景。解决方案是:

self.fakeField.inputView = UIView() // Set an empty, zero-sized view as inputView, in order to remove the standard keyboard
self.fakeField.inputAccessoryView = InputViewCollection // Set your custom keyboard this way instead
于 2018-03-14T20:02:15.957 回答
0

inputViewControllers 和inputViews 似乎有这个灰色的背景。但是,如果您使用inputAccessoryViewControlleror inputAccessoryView,则背景清晰。

于 2021-05-20T09:13:33.083 回答
0

尝试设置后地面视图的 alpha 值,例如InputViewCollection?.alpha = 0.0

于 2017-04-17T22:49:24.820 回答