截断 UITextField 左侧的文本

发布于 2024-10-06 14:14:29 字数 258 浏览 0 评论 0原文

我需要截断 UITextField 左侧的文本。因此,例如,它会显示为“......盲鼠,三只盲鼠,看看它们如何跑”而不是“三只盲鼠,三只盲鼠,看看......”。对于用户来说,字符串的结尾比开头更重要,因此这一点非常重要。

在 UILabel 中,通过将 UILabel 的 lineBreakMode 属性设置为 UILineBreakModeHeadTruncation,这很容易。然而,UITextField似乎没有这样的选项。

有谁知道解决这个问题的简单方法?

I need to truncate text on the left in a UITextField. So, for example, it would show as "... blind mice, three blind mice, see how they run" instead of "three blind mice, three blind mice, see...". It's more important for the user to end of the string, rather than the beginning, so this is quite important.

This is easy enough in a UILabel, by setting UILabel's lineBreakMode property to UILineBreakModeHeadTruncation. However, UITextField seems to have no such option.

Does anyone know an easy way around this?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

画中仙 2024-10-13 14:14:29

如果您通过调用以下代码使键盘可见,则有可能

[self.yourTextField成为FirstResponder];

然后从左侧剪切较大的文本。

您还可以使用以下代码隐藏键盘[如果您使用任何自定义键盘]

// Hide keyboard for Dial Pad, but show blinking cursor
UIView *dummyKeyboardView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 1, 1)];
yourTextField.inputView = dummyKeyboardView;
[dummyKeyboardView release];

It is possible if you make keyboard visible calling following code

[self.yourTextField becomeFirstResponder];

Then larger text is clipped from left.

you can also hide keyboard [if you use any custom keyboard] using following code

// Hide keyboard for Dial Pad, but show blinking cursor
UIView *dummyKeyboardView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 1, 1)];
yourTextField.inputView = dummyKeyboardView;
[dummyKeyboardView release];
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文