Tengo un UITextField en una UITableViewCell. Por alguna razón, el botón borrar no se alinea con el texto del campo textField. Aquí está mi código textField¿Por qué el botón claro no está alineado con el texto en un UITextField?
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];
y aquí está la imagen para demostrar el problema:
Editar: También probé con - (CGRect)clearButtonRectForBounds:(CGRect)bounds
y todavía nada
Muchas gracias por ayudarnos, pero ahora el texto y el botón borrar están alineados en la parte inferior de la celda. Este código realmente alinea el texto, no el botón borrar. Quiero alinear el botón borrar con el centro de la celda ¿Alguna sugerencia? –
¡Funcionó! Acabo de cambiar los atributos de CGRect para que quepan en el botón de borrar –
Gracias. para aclarar, tomé en cuenta la altura de la celda y el campo de texto, para corregir el desplazamiento vertical. CGRect newFrame = albumTitleTextField.frame; newFrame.origin.y = (cell.bounds.size.height - newFrame.size.height)/2.0; [albumTitleTextField setFrame: newFrame]; –