IOS - remove ALL padding from UITextView

后端 未结 5 1960
醉酒成梦
醉酒成梦 2021-01-30 06:22

There are many great examples on SO to remove the left padding of a UITextView.

How to lose margin/padding in UITextView?

However, I need to remove the right pad

5条回答
  •  逝去的感伤
    2021-01-30 06:55

    To completely remove all padding, the lineFragmentPadding must be taken into account.

    let padding = textView.textContainer.lineFragmentPadding
    textView.textContainerInset =  UIEdgeInsets(top: 0, left: -padding, bottom: 0, right: -padding)
    

    The lineFragmentPadding default value is 5, and is at the beginning and end of fragment rectangle.

    Some answers suggested setting lineFragmentPadding to 0. However, as per discussed in the doc, it is not designed to express text margins. So do not set it to 0.

提交回复
热议问题