iOS/Swift : Showing email addresses suggestions on keyboard for UITextFields

标签 ios swift uitextfield inputaccessoryview email-address

在我们的 iOS/iPhone 应用程序之一中,我们需要在注册过程中显示用户配置的电子邮件地址作为建议。有几个应用程序将电子邮件地址显示为键盘输入附件 View 中的固定按钮。例如 Yelp 应用程序(带有 iOS 13.4 的 iPhone 8)

Yelp on iPhone 8 running iOS 13.4

我无法弄清楚如何使用内置方法启用此功能。我尝试将 textContentType、keyboardType 和 autocorrectionType 设置为正确的值,如我可以找到的有关此主题的其他堆栈溢出文章中所述。

这是我的代码

    override func viewDidLoad() {
    super.viewDidLoad()

    let email = UITextField(frame: CGRect(x: 10, y: 60, width: 300, height: 40))
    email.placeholder = "Enter email address here"
    email.font = UIFont.systemFont(ofSize: 15)
    email.borderStyle = UITextField.BorderStyle.roundedRect
    email.clearButtonMode = UITextField.ViewMode.whileEditing
    email.contentVerticalAlignment = UIControl.ContentVerticalAlignment.center
    email.returnKeyType = .continue

    email.keyboardType = .emailAddress
    email.textContentType = .emailAddress
    email.autocorrectionType = .yes
    email.autocapitalizationType = .none

    view.addSubview(email)
}

这就是我在运行 Yelp 应用程序时在装有 iOS 13.4 的同一台 iPhone 8 上的样子:

Test App on the same iPhone 8 running iOS 13.4

没有电子邮件地址建议。

奇怪的是,在我的 iPad 上运行的同一个应用程序会以不同的方式显示建议:

Test App on iPad Pro running iOS 13.3

如何以与 Yelp 相同的方式显示用户的电子邮件地址?是否有我必须使用的特殊 UITextField View ,或者是否有另一种方法来获取电子邮件地址并将其显示在自定义文本附件 View 中?

谢谢你的帮助!

最佳答案

我解决了这个问题,给 UITextField 提供了 accessibilityLabel = "Registration"而不是重命名 View Controller 。

关于iOS/Swift : Showing email addresses suggestions on keyboard for UITextFields,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61006210/

相关文章:

ios - 如何修复出现在内存状态问题上的断点?

iphone - iPhone 的录音格式?

ios - uitableViewCell.background View 行为怪异?

Swift - UI 按钮 : Animated Button crosses the edge

ios - UISegmentedControl 没有触发 UIControlEventValueChanged

ios - 带有@Binding可选属性的SwiftUI View的初始化似乎模棱两可

Swift onclick 文本字段图像

ios - 在键入时获取 UITextField 中的整个文本的简单方法是什么?

ios - 在用户输入时替换字符

objective-c - 切换 View 后 UIText 字段不响应触摸