如何在用户输入上设置UITextView的光标位置? [英] How to set cursor position for UITextView on user input?

查看:189
本文介绍了如何在用户输入上设置UITextView的光标位置?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在为这个问题寻找一个简单的答案...



我有一个 UITextView ,其中用户可以开始输入并单击DONE并辞职。



当想要再次编辑它时,我想让光标(闪烁的线)位于 textView ,而不是在textView的结尾。 (像占位符一样)



我尝试了 setSelectedRange > NSMakeRange(0,0) textViewDidBeginEditing ,但它不工作。



更多信息:



可以看到..当用户点击 textView 光标出现在用户点击 textView



我想让它始终在起始位置闪烁 textViewDidBeginEditing


<因此我最后在 UITextView 中添加了一个UILabel,它作为textView的占位符。点击UILabel会将动作发送到textView和 becomeFirstResponder 。一旦您开始输入,请将标签隐藏。


I am looking for a simple answer for this problem...

I have a UITextView in which the user can start typing and click on DONE and resign the keyboard.

When the wants to edit it again, I want the cursor (the blinking line) to be at the first position of the textView, not at the end of textView. (act like a placeholder)

I tried setSelectedRange with NSMakeRange(0,0) on textViewDidBeginEditing, but it does not work.

More Info:

It can be seen that.. when the user taps on the textView the cursor comes up at the position where the user taps on the textView.

I want it to always blink at starting position when textViewDidBeginEditing.

解决方案

So I ended up adding a UILabel over the UITextView which acts as a placeholder for the textView. Tapping on the UILabel would send the action down to the textView and becomeFirstResponder. Once you start typing, make the label hidden.

这篇关于如何在用户输入上设置UITextView的光标位置?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆