views:

112

answers:

1

Hi, I have an UITextField in an UITableViewCell. For some reason the clear button isn't align to the textField's text. Here's my textField code:


                cell.selectionStyle = UITableViewCellSelectionStyleNone;
                usernameField = [[UITextField alloc] initWithFrame:CGRectMake(22, 10, cell.contentView.frame.size.width, cell.contentView.frame.size.height)];
                usernameField.adjustsFontSizeToFitWidth = YES;
                usernameField.placeholder = @"Username";
                usernameField.backgroundColor = [UIColor clearColor];
                usernameField.keyboardType = UIKeyboardTypeDefault;
                usernameField.autocapitalizationType = UITextAutocorrectionTypeNo;
                usernameField.autocorrectionType = UITextAutocorrectionTypeNo;
                usernameField.returnKeyType = UIReturnKeyNext;
                usernameField.delegate = self;
                usernameField.clearButtonMode = UITextFieldViewModeAlways;
                [usernameField setEnabled:YES];
                [cell addSubview:usernameField];
                [usernameField becomeFirstResponder];
                [usernameField release];            

And here's the picture to demonstrate the problem:

Edit: I also tried with - (CGRect)clearButtonRectForBounds:(CGRect)bounds and still nothing

Thanks!

1: UITextField in UITebleViewCell on Twitpic

+1  A: 

What is your contentVerticalAlignment property? I've seen this issue show up when the clear button is center aligned but the text is aligned the top. Try setting your textfield alignment to the following:

usernameField.contentVerticalAlignment = UIControlContentVerticalAlignmentCenter;

Any luck with that?

Levi Nunnink
Thank you very much for helping, but now the text and the clear button are aligned to the bottom of the cell.I this code you actually align the text, not the clear button.I want to align the clear button to the center of the cellAny suggestions?
Guy Dor
It worked!I just changed the CGRect attributes to fit to the clear button
Guy Dor