UITextField 清除按钮带有占位符错误?
我有一个 UITextField,其clearButton 属性设置为“编辑时”。文本字段右对齐。当我专注于要编辑的文本字段时,占位符文本不会移动,因此插入符号会闪烁,并且一半的占位符文本会被擦除。
有人有解决方法吗?
I've got a UITextField with clearButton property set to "while editing". The textfield is right aligned. When i focus on the textfield to edit, the placeholder text doesn't move so the caret is flashing and half the placeholder text is wiped out.
Does anyone have a workaround?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
我刚刚遇到了完全相同的问题!对我来说,它确实看起来像一个错误——为清除按钮保留的区域将占位符夹到了右侧。
我发现的解决方法是将清除按钮样式更改为“始终”,这是一个用词不当,因为实际上当占位符可见时(即当文本为空时),清除按钮仍然不显示:
它确实意味着占位符未完全向右对齐(为清除按钮留出空间,即使它不存在),如果确实显示了清除按钮,那就太好了!可以通过某种方式确保 UITextField 始终包含空格而不是空白来解决此问题,从而强制清除按钮始终(这意味着始终!) 显示。
I've just hit the exact same issue! It does look like a bug to me -- the area reserved for the clear button clips the placeholder to the right.
The workaround I've found it to change the clear button style to "always", which is a misnomer as in fact the clear button still isn't displayed when the placeholder is visible (i.e. when the text is empty):
It does mean that the placeholder isn't aligned fully to the right (leaving space for the clear button, even though it's not there), which would be fine if the clear button was indeed displayed! This can be fixed by somehow ensuring the UITextField always contains a space instead of a blank, thus forcing the clear button to always (and that means always!) display.
我遇到了同样的问题,我使用文本字段委托方法解决了管理buttonMode(在我的例子中我使用自定义rightView)。具体来说,我实现了这些:
textFieldDidChange:
方法是我为UIControlEventEditingChanged
控件事件添加到 UITextField 的自定义操作。I had the same problem and I solved managing the buttonMode (in my case I'm using a custom rightView) using the textfield delegate methods. In details I implemented these:
The
textFieldDidChange:
method is a custom action that I added to the UITextField for theUIControlEventEditingChanged
control event.我最终通过将前景色更改为银色/灰色来伪造占位符,当用户聚焦时,我清除该 txt 等。
I ended up faking the placeholder by changing the foreground color to silver/gray and when user focuses, i clear out that txt, etc.
这个问题已在 iOS 5 中得到修复:) 谢谢 Apple!
This issue has been fixed in iOS 5 :) Thank you, Apple!