您的位置:首页 > 产品设计 > UI/UE

iOS UITextView设置边距的正确方式

2017-08-05 16:47 651 查看

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;
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  ios textview 间距 边距