Ami*_*ark 5 iphone xcode uitextfield
我有一个UITextField
(放在一个内部UITableViewCell
)有UIButton
一个自定义rightView
:
UITextField *textField = [[[UITextField alloc] initWithFrame:CGRectMake(10.0, 1.0, cell.bounds.size.width - 20.0, 31.0)] autorelease];
textField.autoresizingMask = UIViewAutoresizingFlexibleWidth;
UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
button.bounds = CGRectMake(0.0, 0.0, 27.0, 31.0); // Probably not needed, doesn't change anything
button.frame = CGRectMake(0.0, 0.0, 27.0, 31.0);
[button setImage:[UIImage imageNamed:@"27x31.png"] forState:UIControlStateNormal];
textField.rightView = button;
textField.rightViewMode = UITextFieldViewModeUnlessEditing;
Run Code Online (Sandbox Code Playgroud)
显示文本字段时,不会按预期处理触摸:
如果我将设备旋转到横向模式,情况会变得更糟.在这种情况下,按钮左侧仍然触发按钮的区域较宽,并且该区域左侧有一个间隙,它不执行任何操作 - 按钮未被触发且文本未被编辑.在这种情况下,我必须向左移动以编辑文本.
仅当字段中的当前文本很短时才会发生这种情况.如果文本填充文本字段,则按预期处理触摸(触摸按钮左侧任何位置以纵向和横向编辑文本).
我试图覆盖textRectForBounds
,editingRectForBounds
并且rightViewRectForBounds
.我验证它们被调用并返回正确的值,但它们不会改变任何东西(只要返回值是正确的).
有任何想法吗?
我有一个类似的问题与rightView似乎阻止文本字段的一部分接受输入.我的rightView不是一个按钮所以我只是将它的userInteractionEnabled设置为NO,文本字段开始在整个区域再次接收触摸.
由于你有一个按钮作为rightView,这可能没有多大帮助.但我们的例子之间的另一个相似之处是两个rightViews的宽度都很小.也许rightView不喜欢宽度<x.
您是否为 TableViewCell 设置了任何自动调整大小属性?尝试添加:
[cell setAutoresizingMask:UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight];
Run Code Online (Sandbox Code Playgroud)
文本字段和按钮设置UIViewAutoresizingFlexibleTopMargin
如下选项:
[textField setAutoresizingMask:UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleTopMargin];
[button setAutoresizingMask: UIViewAutoresizingFlexibleTopMargin];
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
3708 次 |
最近记录: |