166

I am doing a login page. I have UITextField for password.

Obviously, I do not want the password to be seen; instead, I want circles to show when typing. How do you set the field for this to happen?

TheNeil
  • 3,321
  • 2
  • 27
  • 52
harsh_017
  • 1,741
  • 2
  • 10
  • 6

9 Answers9

330

Please set your UItextField property secure..

Try this..

textFieldSecure.secureTextEntry = true

textFieldSecure is your UITextField...

For newer Swift version, it is textFieldSecure.isSecureTextEntry = true

Mehul Mistri
  • 15,037
  • 14
  • 70
  • 94
82

One can do this for Obscure a UITextField password:

enter image description here

CODE

Objective-C:

textField.secureTextEntry = YES;

Swift:

textField.isSecureTextEntry = true 
aturan23
  • 4,798
  • 4
  • 28
  • 52
Shekhar Gupta
  • 6,206
  • 3
  • 30
  • 50
37

In Interface Builder check the "Secure Text Entry" checkbox

or

In code set:

Objective-C:

yourTextField.secureTextEntry = YES;

Swift:

yourTextField.secureTextEntry = true
shim
  • 9,289
  • 12
  • 69
  • 108
ipraba
  • 16,485
  • 4
  • 59
  • 58
11

Set the secureTextEntry property to YES.

jtbandes
  • 115,675
  • 35
  • 233
  • 266
8

Open the Xib file and open the inspector of the password text field and tick the secure property.

PgmFreek
  • 6,374
  • 3
  • 36
  • 47
6

For Swift 3.0:

txtpassword.isSecureTextEntry = true
Ahmad F
  • 30,560
  • 17
  • 97
  • 143
somnath
  • 101
  • 1
  • 3
4

in Swift 3.0 or later

passwordTextField.isSecureTextEntry = true
Nandkishor mewara
  • 2,552
  • 16
  • 29
3

Simply check Secure Text Entry check box on the storyboard

enter image description here

Fangming
  • 24,551
  • 6
  • 100
  • 90
  • Is there a way that I can even hide the character to be displayed at all? I don't want the character to be seen at all. – Maninder Singh Aug 01 '19 at 03:51
  • @ManinderSingh Sure but that requires some thinking out of the box. The idea I can think of is to use the text field delegate method to intercept all the inputs. After that return false to any intercepted characters and construct your string by yourself. Take a look at this delegate method `textField(_ textField: UITextField, shouldChangeCharactersIn range: NSRange, replacementString string: String)` – Fangming Aug 01 '19 at 14:04
2
txt_Password = new UITextField {
  Frame = new RectangleF (20,40,180,31),
  BorderStyle = UITextBorderStyle.Bezel,
  TextColor = UIColor.Black,
  SecureTextEntry = true,
  Font = UIFont.SystemFontOfSize (17f),
  Placeholder = "Enter Password",
  BackgroundColor = UIColor.White,
  AutocorrectionType = UITextAutocorrectionType.No,
  KeyboardType = UIKeyboardType.Default,
  ReturnKeyType = UIReturnKeyType.Done,
  ClearButtonMode = UITextFieldViewMode.WhileEditing,
};

secureTextEntry set true.

aturan23
  • 4,798
  • 4
  • 28
  • 52
kiran
  • 4,285
  • 7
  • 53
  • 98