iPhone UITextView 在底部留出 2 行空间

发布于 2024-08-08 06:19:58 字数 124 浏览 2 评论 0原文

当我开始在视图控制器的默认文本视图中输入文本时,它不会到达文本字段的底部。它为另外 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 技术交流群。

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

发布评论

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

评论(4

兰花执着 2024-08-15 06:19:58

由于 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.

爱殇璃 2024-08-15 06:19:58

只是补充马布兹已经说过的话。下面是一些示例代码,可以根据需要进行调整:

    UIEdgeInsets contentInset = notes.contentInset;
    contentInset.bottom = 10.0;
    notes.contentInset = contentInset;

本示例中的注释是 UITextView。

Just adding to what mahboudz already said. Here's some sample code that can be adjusted to get what you need:

    UIEdgeInsets contentInset = notes.contentInset;
    contentInset.bottom = 10.0;
    notes.contentInset = contentInset;

Where notes in this example is the UITextView.

烛影斜 2024-08-15 06:19:58

除了mahboudz和Aaron所说的之外,我可以确认UITextView确实在底部添加了一些contentInset,所以我将以下代码放在textView:shouldChangeTextInRange:replacementText:的里面UITextViewDelegate

textView.contentInset = UIEdgeInsetsMake(0, 0, 5, 0);

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 inside textView:shouldChangeTextInRange:replacementText: of UITextViewDelegate

textView.contentInset = UIEdgeInsetsMake(0, 0, 5, 0);
凉薄对峙 2024-08-15 06:19:58

当从笔尖移动代码以编程方式设置它时,我遇到了类似的问题 - 无论插入点在哪里,它都会向上滚动到视图之外。我最终发现当我以编程方式创建 UITextView 时,它的底部插入了 32 像素,但我不确定为什么。因此,我通过在创建文本视图时设置 contentInset 来修复它:

textView.contentInset = UIEdgeInsetsMake(0, 0, 0, 0);

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:

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