IOS - remove ALL padding from UITextView IOS - remove ALL padding from UITextView ios ios

IOS - remove ALL padding from UITextView


Although it is iOS 7 only, an extremely clean solution is to set the textView's textContainerInsets as such:

[textView setTextContainerInset:UIEdgeInsetsZero];textView.textContainer.lineFragmentPadding = 0; // to remove left padding

This will effectively remove all padding (insets) around the text inside the text view. If your deployment target is iOS 7+ then this is the best solution thus far.


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

let padding = textView.textContainer.lineFragmentPaddingtextView.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.


Swift 4 version for the OA

self.tDescription.textContainerInset = UIEdgeInsets.zeroself.tDescription.textContainer.lineFragmentPadding = 0