我在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];
Run Code Online (Sandbox Code Playgroud)
这是展示问题的图片:

编辑:我也试过,- (CGRect)clearButtonRectForBounds:(CGRect)bounds但仍然没有
Lev*_*ink 19
你的contentVerticalAlignment属性是什么?当清除按钮居中对齐但文本与顶部对齐时,我已经看到此问题出现了.尝试将文本字段对齐设置为以下内容:
usernameField.contentVerticalAlignment = UIControlContentVerticalAlignmentCenter;
Run Code Online (Sandbox Code Playgroud)
运气好吗?
| 归档时间: |
|
| 查看次数: |
3072 次 |
| 最近记录: |