UITextView设置边距的正确方式
项目中的评论发布框的视觉效果需要设置textView中文字距离各个方向的间距,那么正确的设置间距很重要。设置左、右和上间距需要设置textView的textContainerInset属性,设置底间距需要设置contentInset属性。还需设置textView.layoutManager.allowsNonContiguousLayout为NO以防止在打字时会出现抖动现象。
代码如下:
CGFlot xMargin =
12, yMargin =
10;
textView
.textContainerInset = UIEdgeInsetsMake(yMargin, xMargin,
0, xMargin);
textView
.contentInset = UIEdgeInsetsMake(
0,
0, yMargin,
0);
textView
.layoutManager.allowsNonContiguousLayout=
NO;