Я пытаюсь настроить свой UITextField. Я закруглил углы и установил границу 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 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))
}
}
@MikeD., я не думаю, что мне когда-либо приходилось создавать подклассы UITextView, но вы, конечно, могли бы. Это просто UIScrollView, который является UIView. Однако вы можете установить его напрямую с помощью textView.textContainerInset = UIEdgeInsets(top: 0, left: 15, bottom: 0, right: 0). Конечно, используйте любые значения, которые вам нравятся.
Могу ли я сделать что-то подобное с
UITextView?