views:

215

answers:

3

we are trying this for password settings,so that cursor should not be visible to user.

A: 

Try setting the field's secureTextEntry property to YES.

Peter Hosey
actually I want to hide the cursor(make it invisible) while editing the textfield....
darshan
A: 

edit: to answer the question though, hiding the cursor is done easiest by overlaying the UITextField with another UITextField, where the back one is actually the first responder, and the front one acts to at least receive focus (using -(void)textFieldDidBeginEditing:(UITextField *)textField, and passing focus on). In

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

apply the replacement on the front UITextField exactly, using something like

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

You will probably break copy&paste functionality this way. Also, be very careful what you do in those delegate functions. Expect the unexpected.

My original answer, equally applicable:


I don't know what "advanced security" in this context would mean, but have a look at

change the secure password character in uitextfield

To ruin the user experience even more, and maybe add more "security", you could:

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

but I must say that I really don't see the point of all this.

mvds
iPhone have PIN control where we can set password to lock phone, there also u don't find any cursor on textfield. We want to implement the same.
darshan
I know, and my answer gives a solution for that. Have you read it?
mvds
A: 

You can use dummy text field which is hidden and use the delegate textDidChage for TextField and use this value to fill the Masked Values in actual Password field.

In Interface Builder have a dummy textfield which is hidden, maintain a IBOutlet for that say

IBOutlet UITextField *passwordField; IBOutlet UItextField *dummyField;

Also set 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; }
RVN