如何去除inputView下的灰色层swift

How to remove the gray layer under inputView swift

我试图让我的 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)

如何让输入视图的背景保持透明?

谢谢

尝试设置背面Ground View的alpha值 喜欢 InputViewCollection?.alpha = 0.0

使用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

inputViewControllers 和 inputViews 似乎有这个灰色背景。但是,如果你使用inputAccessoryViewControllerinputAccessoryView,那么背景就很清楚了。