How to hide text box cursor on iPhone with keyboard active

we are trying to do this for password settings so that the cursor does not appear to the user.

+4
source share
4 answers
+2
source

edit: to answer the question, although hiding the cursor is easiest by overlaying a UITextField on another UITextField , where the inverse is actually the first responder and the front acts at least to get focus (using -(void)textFieldDidBeginEditing:(UITextField *)textField and focus transfer). IN

 -(BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string 

apply the front-panel replacement to UITextField exactly using something like

 front.text = [front.text stringByReplacingCharactersInRange:range withString:string]; 

This way you are likely to unpack the copy and paste functions. Also, be very careful what you do in these delegate functions. Expect the unexpected.

My initial answer equally applicable:


I don't know what “enhanced security” would mean in this context, but look

change password symbol in uitextfield

To further destroy the user interface and possibly add additional “security”, you could:

  • disable backspace functionality by returning NO if [string length] == 0
  • add 1+(arc4rand()%4) characters for each character entered (as seen from some window systems)
  • add random characters instead of a placeholder constant character

but I have to say that I really do not see the point in this.

+1
source

You can use a dummy text field that is hidden and use the textDidChage delegate for TextField and use this value to populate the Masked Values ​​values ​​in the actual password field.

Interface Builder has a hidden hidden text field that supports IBOutlet saying

IBOutlet UITextField * passwordField; IBOutlet UItextField * dummyField;

Also set a delegate for this and write the following delegate methods

 - (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string{ NSString *dummyText = dummyField.text; NSString *changedText = @""; if(dummyField == textField) { if([string length] == 0) { if([dummyText length] <= 1) { changedText = @""; } else { changedText = [NSString stringWithFormat:@"%@",[dummyText substringToIndex:[dummyText length] - 1]]; } } else { changedText = [NSString stringWithFormat:@"%@%@",dummyText,string]; } passwordField.text = changedText; } return YES; } - (BOOL)textFieldShouldBeginEditing:(UITextField *)textField{ if(passwordField == textField) { [dummyField becomeFirstResponder]; return NO; } return YES; } - (BOOL)textFieldShouldReturn:(UITextField *)textField { [textField resignFirstResponder]; return YES; } 
0
source

I also had this problem. I used the solution described here

It replaces the UITextField with a custom UILabel with the following settings:

  • Override the inputView and inputViewAccessory properties to allow the appearance of the keyboard when the label becomes the first responder.
 @interface PRLabel : UILabel @property (strong, nonatomic, readwrite) UIView* inputView; @property (strong, nonatomic, readwrite) UIView* inputAccessoryView; @end 
To make the label respond to touch events, override the isUserInteractionEnabled method to always return YES. Also, override the touchEnded method to make the label the first responder when a touch is detected. Override the canBecomeFirstResponder method to always return YES. This will provide an input view.
 @implementation PRLabel -(id)initWithFrame:(CGRect)frame { self = [super initWithFrame:frame]; if (self) { // Initialization code } return self; } -(BOOL)isUserInteractionEnabled { return YES; } -(BOOL)canBecomeFirstResponder { return YES; } -(void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event { [self becomeFirstResponder]; } @end 
0
source

All Articles