gpt4 book ai didi

uitableview - 为什么清除按钮不与 UITextField 中的文本对齐?

转载 作者:行者123 更新时间:2023-12-04 16:28:08 26 4
gpt4 key购买 nike

我在 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还是什么都没有

最佳答案

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

usernameField.contentVerticalAlignment = UIControlContentVerticalAlignmentCenter;

运气好吗?

关于uitableview - 为什么清除按钮不与 UITextField 中的文本对齐?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3437884/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com