美文网首页
SwiftUI—使用SecureField密文输入框接收用户的密

SwiftUI—使用SecureField密文输入框接收用户的密

作者: anny_4243 | 来源:发表于2020-07-10 15:40 被阅读0次

原文链接:https://github.com/fzhlee/SwiftUI-Guide#9TextField-SecureField

相当于UITexfield的secureTextEntry的属性设置为true时的情况。
示例代码:

struct ContentView : View {
    
    @State var password : String
    
    var body: some View {
        
        VStack{
            
            Text("Your password is \(password)!")
            
            SecureField("Your password", text: $password) {
                print("Your password is \(self.password)!")
            } //密文输入框,并设置指定占位符,同时设置它的text的值为password属性的值,并通过美元符号和password属性进行绑定包装
            .textFieldStyle(RoundedBorderTextFieldStyle())
            
        }
        .padding()
        
    }
}

相关文章

网友评论

      本文标题:SwiftUI—使用SecureField密文输入框接收用户的密

      本文链接:https://www.haomeiwen.com/subject/qwlmcktx.html