【问题标题】:How do I remove the background under a custom input view for a UITextField如何删除 UITextField 的自定义输入视图下的背景
【发布时间】:2020-05-19 22:26:03
【问题描述】:

我设置了一个UITextField,以便将选择器视图显示为该键盘的输入视图。我希望选择器视图具有圆角,但角下的区域仍显示背景颜色。 pickerView.layer.masksToBound 设置为 true。

我的代码:

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)

【问题讨论】:

    标签: ios swift uikit uikeyboard


    【解决方案1】:

    用于clipToBounds()在角落外剪辑视图..如果您的pickerView在输入视图中,请在输入视图上调用此方法

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

    将此值设置为 true 会导致子视图被裁剪到边界 的接收器。如果设置为 false,则其框架超出的子视图 接收器的可见边界不会被剪裁。默认值 是假的。

    【讨论】:

    • 在代码或情节提要中配置选择器视图的位置?
    • 都是程序化的。
    • 你能用那个代码更新你的问题吗?这样我就可以弄清楚其中有什么问题
    • 可以通过wetransfer分享项目吗?这一切似乎都很好..我想在视图层次结构中看到它
    • 如何发送?我从未使用过 wetransfer 我只看到一种通过电子邮件发送的方式
    猜你喜欢
    • 2016-12-01
    • 2014-11-17
    • 2021-11-06
    • 1970-01-01
    • 1970-01-01
    • 2017-05-11
    • 1970-01-01
    • 2011-08-16
    • 1970-01-01
    相关资源
    最近更新 更多