Clement Bisaillon
Clement Bisaillon

Reputation: 5177

Hide password with "•••••••" in a textField

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?

Upvotes: 159

Views: 202107

Answers (7)

user3731622
user3731622

Reputation: 5095

In Xcode 6.3.1, if you use a NSTextField you will not see the checkbox for secure.

Instead of using NSTextField use NSSecureTextField

https://developer.apple.com/documentation/appkit/nssecuretextfield

I'm guessing this is a Swift/Objective-C change since there is now a class for secure text fields. In the above link it says Available in OS X v10.0 and later. If you know more about when/why/what versions of Swift/Objective-C, Xcode, or OS X this

Upvotes: 13

phil
phil

Reputation: 1003

For SwiftUI, try

TextField ("Email", text: $email)
    .textFieldStyle(RoundedBorderTextFieldStyle()).padding()
SecureField ("Password", text: $password)
    .textFieldStyle(RoundedBorderTextFieldStyle()).padding()

Upvotes: 6

Arunabh Das
Arunabh Das

Reputation: 14372

Programmatically (Swift 4 & 5)

self.passwordTextField.isSecureTextEntry = true

Upvotes: 2

Vicky Dungranee
Vicky Dungranee

Reputation: 23

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

Upvotes: 0

Hatim
Hatim

Reputation: 1522

Swift 4 and Xcode Version 9+

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

Secure Text Entry checked via storyboard screenshot

Upvotes: 17

Nandkishor mewara
Nandkishor mewara

Reputation: 2562

in Swift 3.0 or Later

passwordTextField.isSecureTextEntry = true

Upvotes: 68

meda
meda

Reputation: 45490

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

Upvotes: 336

Related Questions