Как изменить текстовое поле, чтобы курсор не закрывался? - PullRequest
0 голосов
/ 18 мая 2019

Я пытаюсь настроить мой UITextField. Я скругил углы и установил границу textField равной нулю в раскадровке. Я кодировал его так, чтобы при нажатии textField фон textField становился белым, а границы - серым. Однако при запуске приложения граница textField закрывает курсор.

enter image description here

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
    }
}

1 Ответ

0 голосов
/ 18 мая 2019

Я просто использую пользовательский класс для своих полей UITextFields, когда я хочу заполнить.

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))
  }

}
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...