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

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?

You can achieve this directly in Xcode:
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

in Swift 3.0 or Later
passwordTextField.isSecureTextEntry = true

Swift 4 and Xcode Version 9+
Can be set via "Secure Text Entry" via Interface Builder

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

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

Programmatically (Swift 4 & 5)
self.passwordTextField.isSecureTextEntry = true

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

Related

iOS 14 Default user interface style

It seems that Xcode 12 is no longer supporting a default user interface style provided in the info.plist for iOS14. Is this a bug with the beta or is there any other way to provide this information without the need of overwriting every single element?
The following code did the trick
UIApplication.shared.windows.forEach { window in
window.overrideUserInterfaceStyle = .light
}

Black dot in UITextField, instead of Placeholder text, when using Auto Layout in Xcode 9.2

After upgrading to Xcode 9.2, I have had a strange issue in Auto Layout with all the placeholders in my UITextFields.
Did anyone find a solution to this problem?
If using storyboard Just Uncheck secure text entry.
//or if using code
youtTextFieldName.isSecureTextEntry = false

Caret cursor color and size

How do I change the size and colour of the flashing cursor in my textfield using my storyboard for my Mac app.
I assume I have to connect it into the view controller script (control drag) and edit some uitextfield color parameter for the cursor?
But I don't seem to be getting anywhere fast. I am working in swift 2.2 with Mac app Storyboards. Like Ulysses and Taskpaper.
In Swift 3:
Change YOURTEXTFIELD to your textfield and you are set:
(YOURTEXTFIELD.value(forKey: "textInputTraits") as AnyObject).setValue(UIColor.black, forKey: "insertionPointColor")
Documentation: https://developer.apple.com/documentation/appkit/nstextview/1449309-insertionpointcolor
Search for _drawInsertionPointInRect that's the private method that you need. Though you also need some other stuff I think... but it's all mixed into my code so I can't say for sure what it all is. Anyway search for _drawInsertionPointInRect and you'll get to some explanations.

TouchId without Passcode feature

I need for my app to login using TouchId, but I don't want the user to select or fallback into Password option. In other words I'd like to hide the 'Enter Password' label in the figure below. Thanks.
The answer is "Yes".You can hide the "Enter password"...
Try the following code snippet,
var LocalAuthentication = LAContext()
LocalAuthentication.localizedFallbackTitle = "" // Add this line
if LocalAuthentication.canEvaluatePolicy(LAPolicy.DeviceOwnerAuthenticationWithBiometrics, error: &errorMsg){
Add this line before checking for the policy....
LocalAuthentication.localizedFallbackTitle = ""
Hope this might help you..
As far as I know there is no way to hide the password option. Although you can use the device passcode as the fall back.
Please note that the terminology "Passcode" and "Password" refers to different thing in TouchID integration.
"Password" is used for LocalAuthentication approach for integrating TouchID and refering to the applications password as fallback method.
While "Passcode" is referring to the passcode to unlock the device and authenticate purchase in app store.To use the method, you have to store some information to the device's keychain and retrieve it via Touch ID authentication.
See more about these two approaches here
iOS 9 Edit
Based on this answer, iOS 9 provide a new option to hide the passcode option.
For iOS 9, two new policies have been added that do not fallback to passcode. These policies are kSecAccessControlTouchIDAny and kSecAccessControlTouchIDCurrentSet
Per documentation from LocalAuthentication.LAContext:
/// Fallback button title.
/// #discussion Allows fallback button title customization. A default title "Enter Password" is used when
/// this property is left nil. If set to empty string, the button will be hidden.
open var localizedFallbackTitle: String?

login form in iphone native application

I am trying to do the login form I have created two uitextfields for username ,password and one uibutton for login. when I enter password in password textfield I want to display all the text as '*' or any special characters like in the following images
Is there any default ways in sdk to do this or we have to do it logically if any give me some sample codes? Thanks in advance
The UITextInputField conforms to the UITextInputTraits protocol, which means you can use the following to tell it to display "*"s:
[passwordTextInputField setSecureTextEntry:YES];
Open you NIB-File in Interface-Builder, mark your UITextField and open the Inspector (Tools > Inspector). In the very left Tab (Attributes) set the value of "Secure" to TRUE.
See the Screenshot below:
Programmaticaly you can use the following line of Code:
password.secureTextEntry = TRUE
Where password is your UITextField.
You can use [myTextField setSecureTextEntry:YES] which is part of the UITextInputTraits protocol whom UITextField adhere.
Don't know of a "free" way to change the secure character, though.