为什么clear按钮与UITextField中的文本不对齐?

时间:2010-08-09 06:55:08

标签: uitableview uitextfield

我在UITableViewCell中有一个UITextField。 由于某种原因,清除按钮未与textField的文本对齐。 这是我的textField代码:


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];

以下是展示问题的图片: Screenshot

编辑: 我也试过了- (CGRect)clearButtonRectForBounds:(CGRect)bounds但仍然没有

1 个答案:

答案 0 :(得分:19)

您的contentVerticalAlignment属性是什么?当清除按钮居中对齐但文本与顶部对齐时,我已经看到此问题出现了。尝试将文本字段对齐设置为以下内容:

usernameField.contentVerticalAlignment = UIControlContentVerticalAlignmentCenter;

运气好吗?