iOS UITextView设置边距的正确方式

UITextView设置边距的正确方式

项目中的评论发布框的视觉效果需要设置textView中文字距离各个方向的间距,那么正确的设置间距很重要。设置左、右和上间距需要设置textView的textContainerInset属性,设置底间距需要设置contentInset属性。还需设置textView.layoutManager.allowsNonContiguousLayout为NO以防止在打字时会出现抖动现象。

代码如下:

CGFlot xMargin =12, yMargin = 10;
// 使用textContainerInset设置top、left、right
textView.textContainerInset = UIEdgeInsetsMake(yMargin, xMargin, 0, xMargin);
//当光标在最后一行时,始终显示低边距,需使用contentInset设置bottom.
textView.contentInset = UIEdgeInsetsMake(0, 0, yMargin, 0);
//防止在拼音打字时抖动
textView.layoutManager.allowsNonContiguousLayout=NO;
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章