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;
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章