iPhone UITextView 在底部留出 2 行空间
当我开始在视图控制器的默认文本视图中输入文本时,它不会到达文本字段的底部。它为另外 2 行文本留出空间,然后开始滚动。 我希望当我开始超出最后一行时它开始滚动。
我尝试了一切,但我不知道我能做什么? 有人有什么想法吗?
When I start typing text in a default textView in my viewcontroller, it's not going to the bottom of the textfield. It leaves room for 2 more lines of text and then starts scrolling.
I want it to start scrolling when I start going beyond the last line.
I tried everything, and I don't know what I can do?
Anyone any ideas?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
由于 UITextView 是 UIScrollView 的子类,请查看 UIScrollVIew 的属性,例如 contentInset 等,看看它们是否可能在框架/边界与内部内容之间创建间隙。
as UITextView is a subclass of UIScrollView, look at UIScrollVIew's properties, like contentInset and others to see if they might be creating a gap between your frame/bounds and the content inside.
只是补充马布兹已经说过的话。下面是一些示例代码,可以根据需要进行调整:
本示例中的注释是 UITextView。
Just adding to what mahboudz already said. Here's some sample code that can be adjusted to get what you need:
Where notes in this example is the UITextView.
除了mahboudz和Aaron所说的之外,我可以确认UITextView确实在底部添加了一些
contentInset
,所以我将以下代码放在textView:shouldChangeTextInRange:replacementText:
的里面UITextViewDelegate
In addition to what mahboudz and Aaron said, I can confirm that UITextView does add some
contentInset
to the bottom, so I put the following code insidetextView:shouldChangeTextInRange:replacementText:
ofUITextViewDelegate
当从笔尖移动代码以编程方式设置它时,我遇到了类似的问题 - 无论插入点在哪里,它都会向上滚动到视图之外。我最终发现当我以编程方式创建 UITextView 时,它的底部插入了 32 像素,但我不确定为什么。因此,我通过在创建文本视图时设置 contentInset 来修复它:
When moving code from a nib to setting it up programmatically, I ran into a similar problem--wherever the insertion point was, it was scrolled up out of view. I eventually found that my UITextView had a bottom inset of 32 pixels when I created it programmatically, though I'm not sure why. So I fixed it by setting the contentInset when I create the text view: