How do I remove the background under a custom input view for a UITextField

Viewed 275

I have set up a UITextField in order to display a picker view as an input view for this keyboard. I want the picker view to have rounded corners however the area under the corners still displays a background color. pickerView.layer.masksToBound is set to true.

My Code:

dummyTextField.delegate = self

pickerView.delegate = self
pickerView.dataSource = self

pickerView.frame = CGRect(x: 0, y: 0, width: screenWidth, height: 150)
pickerView.backgroundColor = offWhite
pickerView.layer.cornerRadius = 15
pickerView.layer.borderWidth = CGFloat(borderWidth)
pickerView.layer.borderColor = blue.cgColor
pickerView.layer.masksToBounds = true
pickerView.clipsToBounds = true

dummyTextField.inputView = pickerView
dummyTextField.inputView?.clipsToBounds = true

let pickerToolBar = UIToolbar()
let pickerDoneButton = UIBarButtonItem(title: "Done", style: .done, target: self, action: #selector(pickerDone))
pickerDoneButton.tintColor = blue

//I also added the toolbar here

self.window.addSubview(dummyTextField)

My Simulator

1 Answers

Use to clipToBounds() clip view outside corners.. if your pickerView is in input view call this method on input view

pickerView.clipToBounds = true
textField.inputView?.clipsToBounds = true

Setting this value to true causes subviews to be clipped to the bounds of the receiver. If set to false, subviews whose frames extend beyond the visible bounds of the receiver are not clipped. The default value is false.

Related