iOS UITextView设置边距的正确方式

xiaoxiao2021-02-28  131

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;
转载请注明原文地址: https://www.6miu.com/read-28552.html

最新回复(0)