Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to remove the gray layer under inputView swift

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

like image 794
corocraft Avatar asked Nov 28 '25 06:11

corocraft


1 Answers

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
like image 69
Frederik Avatar answered Nov 30 '25 20:11

Frederik