如何快速去除inputView下的灰色层

cor*_*aft 2 uitextfield ios 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)
Run Code Online (Sandbox Code Playgroud)

如何离开输入视图的透明背景?

谢谢

Fre*_*rik 6

使用时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
Run Code Online (Sandbox Code Playgroud)