ChatGPT解决这个技术问题 Extra ChatGPT

Obscure a UITextField password

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?


L
Lukas Würzburger

Please set your UItextField property secure..

Try this..

textFieldSecure.secureTextEntry = true

textFieldSecure is your UITextField...


It has been changed to isSecureTextEntry in the new swift versions
a
aturan23

One can do this for Obscure a UITextField password:

https://i.stack.imgur.com/degAl.png

CODE

Objective-C:

textField.secureTextEntry = YES;

Swift:

textField.isSecureTextEntry = true 

s
shim

In Interface Builder check the "Secure Text Entry" checkbox

or

In code set:

Objective-C:

yourTextField.secureTextEntry = YES;

Swift:

yourTextField.secureTextEntry = true

j
jtbandes

Set the secureTextEntry property to YES.


P
PgmFreek

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


A
Ahmad F

For Swift 3.0:

txtpassword.isSecureTextEntry = true

Why are you just repeating the previous answers
where u see the ans.
N
Nandkishor mewara

in Swift 3.0 or later

passwordTextField.isSecureTextEntry = true

F
Fangming

Simply check Secure Text Entry check box on the storyboard

https://i.stack.imgur.com/PPsEt.gif


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.
@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)
a
aturan23
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.