UITextView去掉单行的边距以及各种坑

来源:互联网 发布:多功能双肩背包 知乎 编辑:程序博客网 时间:2024/06/07 03:39
self.textView.textContainer.lineFragmentPadding = 0;  self.textView.textContainerInset = UIEdgeInsetsZero;  

只需要以上两行代码即可。这样我们在UITextView中设置的文字就可以左右两边对齐显示。

lineFragmentPading:官方描述:

The amount by which text is inset within line fragment rectangles.

The padding appears at the beginning and end of the line fragment rectangles. The layout manager uses this value to determine the layout width. The default value of this property is 5.0. 

Line fragment padding is not designed to express text margins. Instead, you should use insets on your text view, adjust the paragraph margin attributes, or change the position of the text view within its superview.


===============================坑2=============

设置textView的文字后,自动滚动到底部问题:

原问题描述地址:点击打开链接

利用上述方法会发现每当view出现的时候会滚动一下,用下面的方法可以完美解决,

解决方法:

[_contentLabel scrollRectToVisible:CGRectZero animated:NO];


阅读全文
0 0
原创粉丝点击