在我们的 iOS/iPhone 应用程序之一中,我们需要在注册过程中显示用户配置的电子邮件地址作为建议。有几个应用程序将电子邮件地址显示为键盘输入附件 View 中的固定按钮。例如 Yelp 应用程序(带有 iOS 13.4 的 iPhone 8)
我无法弄清楚如何使用内置方法启用此功能。我尝试将 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 上的样子:
没有电子邮件地址建议。
奇怪的是,在我的 iPad 上运行的同一个应用程序会以不同的方式显示建议:
如何以与 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/