为 UITextField 设置 contextType 无效

Setting contextType for UITextField is not working

不知道为什么,但我的 textField 没有响应设置 contextType...

这就是我创建 textField 的方式:

let emailTextField: UITextField = {
    let v = UITextField()
    v.textColor = .white
    v.font = UIFont(name: "AvenirNext-Regular", size: 17)
    v.placeholder = "Email-Adresse"
    v.textContentType = .emailAddress
    v.minimumFontSize = 13
    v.borderStyle = .line
    v.autocapitalizationType = .none
    v.translatesAutoresizingMaskIntoConstraints = false
    return v
}()

它显示得很好,一切正常,但 contextType...它只显示标准键盘。我做错了什么吗??

您可以使用 keyboardType 来设置键盘,如下所示:

v.keyboardType = .emailAddress