如何修改文本字段以使光标不被覆盖?

How do I modify the text field so the cursor is not covered?

我正在尝试自定义 UITextField。我在故事板中圆角并将 textField 边框设置为 none。我对其进行了编码,以便在点击 textField 时,textField 背景变为白色,边框变为灰色。但是,当我 运行 应用程序时,textField 边框覆盖了光标。

func textFieldDidBeginEditing(_ textField: UITextField) {
    // Change the background color for the textField and change the border width for the textField.
    textField.backgroundColor = UIColor.white
    textField.layer.borderWidth = 2
    textField.layer.borderColor = #colorLiteral(red: 0.9373082519, green: 0.9373301864, blue: 0.9373183846, alpha: 1)

    // Disable the doneButton while editing.
    doneButton.isEnabled = false
}

func textFieldDidEndEditing(_ textField: UITextField) {
    // Change the background color for the textField and change the border width for the textField.
    textField.backgroundColor = #colorLiteral(red: 0.9373082519, green: 0.9373301864, blue: 0.9373183846, alpha: 1)
    textField.layer.borderWidth = 0

    // Enable the doneButton when finished editing.
    doneButton.isEnabled = true

    // Set the title of the navigation bar to the text from the titleTextField.
    if titleTextField.text != "" {
        navigationItem.title = titleTextField.text
    }
}

我只是在需要填充时为我的 UITextFields 使用自定义 class。

class PaddedTextField: UITextField {

  override func textRect(forBounds bounds: CGRect) -> CGRect {
    return bounds.inset(by: UIEdgeInsets.init(top: 0, left: 15, bottom: 0, right: 0))
  }

  override func placeholderRect(forBounds bounds: CGRect) -> CGRect {
    return bounds.inset(by: UIEdgeInsets.init(top: 0, left: 15, bottom: 0, right: 0))
  }

  override func editingRect(forBounds bounds: CGRect) -> CGRect {
    return bounds.inset(by: UIEdgeInsets.init(top: 0, left: 15, bottom: 0, right: 0))
  }

}