UITextView 文本在顶部对齐
我正在使用 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我有类似的东西,可以根据用户输入加载可滚动图像,这可能有帮助,也可能没有帮助。每次用户更改图像时,我都会调用:
[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.
使用这个:
self.nameTextView.contentInset = UIEdgeInsetsMake(0,0,0,0);
Use this :
self.nameTextView.contentInset = UIEdgeInsetsMake(0,0,0,0);
您是否尝试使用
[<#Your textview#>大小适合];
did you try with
[<#Your textview#> sizeToFit];