类似于iPhone上的短信应用程序的文本输入框

发布于 2024-08-23 08:47:45 字数 452 浏览 4 评论 0原文

我在尝试获取像短信应用程序中那样的输入框时遇到了麻烦。

任何人都可以提供一些关于如何构建其中之一并使其看起来不错的指导吗?我需要一个形状与 UITextfield 类似的输入框,但在打字时会垂直拉伸。

我假设我需要计算文本的宽度并在文本换行时垂直拉伸覆盖图像框架。我最接近的确实会拉伸,但当接近边界时光标会四处弹跳。

更新:

我每天都在为此工作一周,我几乎放弃了 UITextView。我可以让它正确拉伸,但是当退格时,Textview 高度在向上一行时收缩太多。当我继续退格时,它会自行纠正。例如,当我在第 4 行并退格到第 3 行时,它会显示此行为。然后当我继续退格时,它会进行纠正,直到我到达第 2 行的末尾。然后它会自行纠正,.... 等等。

我决定尝试对 UITextField 进行子类化,但我什至无法让它以我指定的帧大小显示。 150,150,150,150。

I am having a terrible time trying to get an input box like the one in the SMS app.

Can anyone offer some guidance on how to build one of these and make it look good? I need an input box that is shaped nicely like the UITextfield but will stretch vertically when typing.

I assume that I need to calculate width of the text and stretch the overlay image frame vertically when the text word wraps. The closest I have come does stretch but the cursor bounces all around when nearing the boundaries.

UPDATE:

I have worked on this everyday for a week and I have about given up on the UITextView. I can get it to stretch properly but when backspacing, the Textview height shrinks too much when going up a line. As I continue backspacing it corrects itself. For example, it displays this behavior when I am on line 4 and backspace up to line 3. Then as I continue backspacing, it corrects until I get to the end of line 2. Then it corrects itself,.... etc.

I decided to try to subclass UITextField but I can't even get it to display in the Frame size that I specify. 150,150,150,150.

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

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

发布评论

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

评论(4

各空 2024-08-30 08:47:46

我知道这已经过时了,但对于仍然关注这个答案的人来说,现在 Slack 提供了一个很好的控件,可以实现名为 SlackTextViewController

I know this is old but for the people that still look at this answer there is now a nice control from Slack that does that called SlackTextViewController.

也只是曾经 2024-08-30 08:47:45

尝试聊天输入示例。它具有与短信应用程序类似的外观和功能。

Try Chat Input Sample. It has the similar look and functionality of SMS app.

抠脚大汉 2024-08-30 08:47:45

Three20 项目有一个控件可以为您执行此操作。

来自 Three20 自述文件:

TTTextEditor是一个UITextView,它可以
随着你的身高自动增长
类型。我用它来输入消息
在 Facebook 聊天中,它的行为
类似于苹果短信中的编辑器
应用程序。

Three20 project has a control that should do this for you.

From the Three20 README:

TTTextEditor is a UITextView which can
grow in height automatically as you
type. I use this for entering messages
in Facebook Chat, and it behaves
similarly to the editor in Apple's SMS
app.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文