如何在SwiftUI中设置TextField的键盘类型? [英] How to set Keyboard type of TextField in SwiftUI?

查看:1352
本文介绍了如何在SwiftUI中设置TextField的键盘类型?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我似乎找不到任何信息或找不到如何在SwiftUI的TextField上设置键盘类型. 能够启用安全文本属性,隐藏密码等也是很好的选择.

I can't seem to find any information or figure out how to set the keyboard type on a TextField for SwiftUI. It would also be nice to be able to enable the secure text property, to hide passwords etc.

这篇文章显示了如何包装" UITextField,但是如果不需要的话,我宁愿不使用任何UI控件. 如何使TextField成为第一响应者?

This post shows how to "wrap" a UITextField, but I'd rather not use any UI-controls if I don't have to. How to make TextField become first responder?

任何人都知道如何在不包装旧式UI控件的情况下完成此操作吗?

Anyone have any ideas how this can be done without wrapping an old school UI control?

推荐答案

要创建一个可以在其中输入安全文本的字段,可以使用SecureField($password)

To create a field where you can enter secure text you can use SecureField($password)

https://developer.apple.com/documentation/swiftui/securefield

如果要将textField的contentType设置为例如. .oneTimeCode,您可以这样做.也适用于keyboardType

If you want to set the contentType of an textField to eg. .oneTimeCode you can do it like this. Also works with keyboardType

TextField($code)
    .textContentType(.oneTimeCode)
    .keyboardType(.numberPad)

这篇关于如何在SwiftUI中设置TextField的键盘类型?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆