MDCTextInputController错误消息会覆盖输入的文本

时间:2019-07-20 01:50:58

标签: ios swift textfield material-components-ios

使用material-components / material-components-ios v85.8.0

import MaterialComponents

....

var usernameTextField = MDCTextField()
var userNameTextLayout = MDCTextInputControllerUnderline()
usernameTextField = {
    let usernameTextEdit = MDCTextField()
    usernameTextEdit.translatesAutoresizingMaskIntoConstraints = false
    usernameTextEdit.clearButtonMode = .unlessEditing
    usernameTextEdit.backgroundColor = .white
    return usernameTextEdit
}()
userNameTextLayout.textInput = usernameTextField
userNameTextLayout.placeholderText = "Username"
// add to view
....

private func isUserNameValid() -> Bool {
    let enteredUsername = usernameTextField.text ?? ""
    if (!enteredUsername.isValidEmail) {
        userNameTextLayout.setErrorText("Invalid e-mail address",
                                        errorAccessibilityValue: nil)
        return false
    }
}

错误消息涵盖了输入的文本,看起来很糟糕: iOS

但是,Android材质设计确实将错误置于行下: Android

想知道是否有办法做到这一点,或者我做错了什么。

我遵循了他们的教程:https://codelabs.developers.google.com/codelabs/mdc-101-swift/#2

1 个答案:

答案 0 :(得分:0)

我将MDCTextField的高度设置得太小。通过将其从50-> 80pts增大,可以达到目的,并将错误消息移至该行下方。