UITextView 文本在顶部对齐

发布于 2024-08-14 16:28:47 字数 178 浏览 2 评论 0原文

我正在使用 UITextView 显示从 XML 文件读取的文本。单击按钮后,它将从 XML 文件中读取下一个条目,并相应地替换文本视图中的文本。 它工作正常。 但问题是,有时,文本从文本视图中的 0,0 位置开始,有时,它在文本视图的顶部留下一些空间并显示文本。 如何强制文本与文本视图的顶部对齐。 另外,如何使文本视图在顶部留下一些填充?

I'm using UITextView to display a text read from XML file. On click of a button, it will read next entry from XML file and replaces text in text view accordingly.
Its working fine.
But the trouble is that, some times, the text starts at 0,0 location in text view and some times, its leaving some space at the top of text view and displaying text.
How can I force text to align to the top of text view.
Also how can I make text view to leave some padding at the top?

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

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

发布评论

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

评论(3

苹果你个爱泡泡 2024-08-21 16:28:47

我有类似的东西,可以根据用户输入加载可滚动图像,这可能有帮助,也可能没有帮助。每次用户更改图像时,我都会调用:
[YourTextView setContentOffset:CGPointZero];

它可能有助于重置文本视图的位置。

I have something similar with scrollable images loading based on user input, which may or may not help. Every time the user changes the image I call:
[YourTextView setContentOffset:CGPointZero];

It might help reset the positioning of the text view.

魂牵梦绕锁你心扉 2024-08-21 16:28:47

使用这个:
self.nameTextView.contentInset = UIEdgeInsetsMake(0,0,0,0);

Use this :
self.nameTextView.contentInset = UIEdgeInsetsMake(0,0,0,0);

水溶 2024-08-21 16:28:47

您是否尝试使用 [<#Your textview#>大小适合];

did you try with [<#Your textview#> sizeToFit];

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