Код: Выделить всё
private lazy var errorLabel: UILabel = {
let label = UILabel()
label.font = UIFont.systemFont(ofSize: 14, weight: .bold)
label.textColor = errorColor
label.numberOfLines = 0
label.isHidden = true
return label
}()
open override func didMoveToSuperview() {
super.didMoveToSuperview()
// Make sure that errorLabel is added once to the superview, not to the text field itself
if let superview = superview, errorLabel.superview == nil {
superview.addSubview(errorLabel)
configureErrorLabelConstraints()
}
}
private func configureErrorLabelConstraints() {
errorLabel.translatesAutoresizingMaskIntoConstraints = false
NSLayoutConstraint.activate([
errorLabel.topAnchor.constraint(equalTo: self.bottomAnchor, constant: 5),
errorLabel.leadingAnchor.constraint(equalTo: self.leadingAnchor),
errorLabel.trailingAnchor.constraint(equalTo: self.trailingAnchor)
])
public func showInlineValidationError(message: String) {
errorLabel.textColor = errorColor
layer.borderColor = errorColor.cgColor
errorLabel.text = message
errorLabel.isHidden = false
}
public func hideInlineValidationError() {
layer.borderColor = borderColor.cgColor
errorLabel.isHidden = true
}
}
Я открыт для сторонней библиотеки, если она достаточно проста. Мне просто нужно базовое поле UITextfield с закругленными углами и меткой ошибки ниже, которая может удовлетворить мои требования к изменению высоты
Подробнее здесь: https://stackoverflow.com/questions/783 ... tion-error
Мобильная версия