我试图让我的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)
如何保留输入视图的透明背景?
由于
答案 0 :(得分:3)
使用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
答案 1 :(得分:0)
尝试设置背景视图的alpha值
比如InputViewCollection?.alpha = 0.0
答案 2 :(得分:0)
inputViewController
和 inputView
似乎具有这种灰色背景。但是,如果您使用 inputAccessoryViewController
或 inputAccessoryView
,则背景清晰。