2

I'm trying to leave the background of my Inputview transparent but I only get it gray.

enter image description here

The code is:

    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)

How can I leave transparent background of a inputview?

Thanks

corocraft
  • 150
  • 3
  • 13

3 Answers3

7

When using inputView, you have to use the width of the standard keyboard. However, you can set an empty view as the inputView, and set your custom keyboard as the inputAccessoryView instead. This doesn't have a grey background. The solution would be:

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
Frederik
  • 384
  • 3
  • 7
0

try to set alpha value of back Ground View like InputViewCollection?.alpha = 0.0

Manvir Singh
  • 129
  • 2
  • 11
0

inputViewControllers and inputViews seem to have this gray background. However if you use inputAccessoryViewController or inputAccessoryView, then the background is clear.

Stoyan
  • 1,265
  • 11
  • 20