我正在尝试使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)
如何保持InputView的透明背景?
谢谢
最佳答案
使用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
关于ios - 如何删除inputView swift下的灰色层,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/43460164/