问题
I am creating an app that requires the use of a USB Keyboard. (The normal touch screen keyboard has been disabled and will not show up.) When the user installs the app for this first time, they will need to create a four digit Pin. The input field for the Pin is password protected (as in dots will appear every time a new digit is entered). The Pin UITextField is set up to only except four numeric digits. Any other letters/numbers will not be added to the UITextField. This is what it looks like -
Link to the image.
The problem here is when the user clicks the caps lock button on the USB keyboard, the caps lock image will appear in the UITextField. However, the field only accepts numbers, so I don't care to show a caps lock image in the text field. Is there a way I can remove the caps lock image?
回答1:
Adding a dummy view to the rightView did the trick. Thanks for the input.
textField.rightView = UIView(frame: CGRect(x: 0, y: 0, width: 0, height: 0))
回答2:
There is no clean way to do this (that I know of), but it can be done by placing a white image over were the caps lock appears.
This way, the caps lock image will always be hidden.
Make sure to place the NSImageView control after the NSSecureTextView control (in the UI Builder), so the image will be drawn after the NSSecureTextView control is drawn.
回答3:
You can add Images to the textfiled like in the way given in the sample code given below:
Swift add icon/image in UITextField
But to check if you caps lock is on or not, I think there isn't any proper way to do that. Maybe you can check in "textFieldShouldReturn" method if the typed character is uppercase or lower case, every-time time when user types a character.
来源:https://stackoverflow.com/questions/43856344/caps-lock-image-on-password-protected-uitextfield