【问题标题】:How to remove the gray layer under inputView swift如何快速去除inputView下的灰色层
【发布时间】:2017-09-13 14:00:44
【问题描述】:

我试图让我的 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 保持透明背景?

谢谢

【问题讨论】:

    标签: ios swift uitextfield inputview


    【解决方案1】:

    使用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
    

    【讨论】:

    • 哇,非常感谢你的精彩回答,这拯救了我的一周:)
    【解决方案2】:

    尝试设置背面地面视图的 alpha 值 喜欢InputViewCollection?.alpha = 0.0

    【讨论】:

    • 如果我设置 InputViewCollection?.alpha = 0.0,那么所有视图都是灰色的。它不起作用。
    【解决方案3】:

    inputViewControllers 和inputViews 似乎有这种灰色背景。但是如果你使用inputAccessoryViewControllerinputAccessoryView,那么背景是清晰的。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-04-24
      • 1970-01-01
      • 1970-01-01
      • 2016-02-02
      • 1970-01-01
      相关资源
      最近更新 更多