Hide password with “•••••••” in a textField

前端 未结 7 1856
时光说笑
时光说笑 2020-12-23 02:20

In my app there is a textField where the user have to put is password in and i want that when he enter a character it change it to \'•\' how can i do this?

相关标签:
7条回答
  • 2020-12-23 03:05

    For SwiftUI, try

    TextField ("Email", text: $email)
        .textFieldStyle(RoundedBorderTextFieldStyle()).padding()
    SecureField ("Password", text: $password)
        .textFieldStyle(RoundedBorderTextFieldStyle()).padding()
    
    0 讨论(0)
  • 2020-12-23 03:08

    You can do this by using properties of textfield from Attribute inspector

    Tap on Your Textfield from storyboard and go to Attribute inspector , and just check the checkbox of "Secure Text Entry" SS is added for graphical overview to achieve same

    0 讨论(0)
  • 2020-12-23 03:10

    Programmatically (Swift 4 & 5)

    self.passwordTextField.isSecureTextEntry = true
    
    0 讨论(0)
  • 2020-12-23 03:12

    You can achieve this directly in Xcode:

    enter image description here

    The very last checkbox, make sure secure is checked .

    Or you can do it using code:

    Identifies whether the text object should hide the text being entered.

    Declaration

    optional var secureTextEntry: Bool { get set }
    

    Discussion

    This property is set to false by default. Setting this property to true creates a password-style text object, which hides the text being entered.

    example:

    texfield.secureTextEntry = true
    
    0 讨论(0)
  • 2020-12-23 03:15

    Swift 4 and Xcode Version 9+

    Can be set via "Secure Text Entry" via Interface Builder

    0 讨论(0)
  • 2020-12-23 03:23

    in Swift 3.0 or Later

    passwordTextField.isSecureTextEntry = true
    
    0 讨论(0)
提交回复
热议问题