简体   繁体   English

文本输入框就像iPhone上的短信应用程序一样

[英]Text input box like the SMS app on the iPhone

I am having a terrible time trying to get an input box like the one in the SMS app. 我正在尝试获取像SMS应用程序中的输入框那样糟糕的时间。

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. 我需要一个输入框,其形状很好,就像UITextfield一样,但在打字时会垂直拉伸。

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. 我已经每天工作了一个星期,我已经放弃了UITextView。 I can get it to stretch properly but when backspacing, the Textview height shrinks too much when going up a line. 我可以让它适当地伸展,但是当退格时,Textview高度在上线时会收缩太多。 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. 例如,当我在第4行并退回到第3行时,它会显示此行为。然后,当我继续退格时,它会更正,直到我到达第2行的末尾。然后它会自行更正,......等等。

I decided to try to subclass UITextField but I can't even get it to display in the Frame size that I specify. 我决定尝试子类UITextField,但我甚至不能让它以我指定的Frame大小显示。 150,150,150,150. 150150150150。

Try Chat Input Sample . 尝试聊天输入示例 It has the similar look and functionality of SMS app. 它具有与SMS应用程序类似的外观和功能。

Three20 project has a control that should do this for you. Three20项目有一个控件,应该为你做这个。

From the Three20 README: 来自Three20自述文件:

TTTextEditor is a UITextView which can grow in height automatically as you type. TTTextEditor是一个UITextView,它可以在您键入时自动增长。 I use this for entering messages in Facebook Chat, and it behaves similarly to the editor in Apple's SMS app. 我使用它在Facebook Chat中输入消息,它的行为与Apple的SMS应用程序中的编辑器类似。

我知道这已经过时了,但对于那些仍然关注这个答案的人来说,Slack现在有一个很好的控制方法就是SlackTextViewController

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM