Mistery insets of UITextView

Arthur Wang 的泡面番
1 min readJul 1, 2019

--

If you try to use `boundingRect(with:)` to calculate text’s size and set the size back to a label, it’d work just fine. But if you change `UILabel` to `UITextView`, it would have extra paddings around.

The trick here is the `contentInset`/`textContainerInset`/`textContainer.lineFragmentPadding` all need to be set to zero. `textContainer.lineFragmentPadding` is the last piece the screenshot doesn’t show.

--

--