1

I am attempting to set the contentInsets to zero for my textView that I place inside my tableViewCells so that I can align my text with the label and imageView bubble. My current implementation looks like this. enter image description here

I adopted the solution in this post but does not seem to work for my case. Blank space at top of UITextView in iOS 10

The solution in the above post is for uiviews but mine is in a tableViewCell, which automaticallyAdjustsScrollViewInsets is not available in tableViewCell.

Any help here pls?

Koh
  • 2,687
  • 1
  • 22
  • 62

1 Answers1

3

Setting contentInset to zero will not work since it's applied to UIScrollView.

The spacing that you want to remove is actually controlled by NSTextContainer inside of UITextView.

To remove the spacing just put this in your cell (for example inside awakeFromNib):

override func awakeFromNib() {
    super.awakeFromNib()

    // Removes UITextView inner spacing
    textView.textContainerInset = .zero
    textView.textContainer.lineFragmentPadding = 0.0
}
Crt Gregoric
  • 392
  • 1
  • 5
  • 12