Swift - добавление кнопки очистки в UITextfield программно - PullRequest
1 голос
/ 23 января 2020

У меня проблемы с добавлением кнопки очистки к моему UITextfield.

Это мое textfield:

let emailTextField: CustomTextField = {
    let v = CustomTextField()
    v.borderActiveColor = .white
    v.borderInactiveColor = .white
    v.textColor = .white
    v.font = UIFont(name: "AvenirNext-Regular", size: 17)
    v.placeholder = "Email-Adresse"
    v.placeholderColor = .gray
    v.placeholderFontScale = 1
    v.clearButtonMode = UITextField.ViewMode.always
    v.minimumFontSize = 13
    v.borderStyle = .line
    v.autocapitalizationType = .none
    v.translatesAutoresizingMaskIntoConstraints = false
    return v
}()

Как видите, я установил clearButtonMode = .always, но это не отображается.

Мой CustomTextFieldClass тоже ничего особенного:

class CustomTextField: HoshiTextField {

    /// the left padding
    @IBInspectable public var leftPadding: CGFloat = 0 { didSet { self.setNeedsLayout() } }

    /// the right padding
    @IBInspectable public var rightPadding: CGFloat = 0 { didSet { self.setNeedsLayout() } }

    /// Text rectangle
    ///
    /// - Parameter bounds: the bounds
    /// - Returns: the rectangle
    override public func textRect(forBounds bounds: CGRect) -> CGRect {
        let originalRect: CGRect = super.editingRect(forBounds: bounds)
        return CGRect(x: originalRect.origin.x + leftPadding, y: originalRect.origin.y, width: originalRect.size.width - leftPadding - rightPadding, height: originalRect.size.height)
    }

    /// Editing rectangle
    ///
    /// - Parameter bounds: the bounds
    /// - Returns: the rectangle
    override public func editingRect(forBounds bounds: CGRect) -> CGRect {
        let originalRect: CGRect = super.editingRect(forBounds: bounds)
        return CGRect(x: originalRect.origin.x + leftPadding, y: originalRect.origin.y, width: originalRect.size.width - leftPadding - rightPadding, height: originalRect.size.height)
    }

Кто-нибудь знает, почему кнопка очистки не отображается ???

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