ios – TextView provides backside padding/house when textual content is one line

[ad_1]

Situation

I’m experiencing a bizarre behaviour with a UITextView which is inside a UIStackView with an outlined spacing of 0. The UITextView is used to show a message inside a chat bubble. When the message is just one line, the UITextView expands and provides a backside spacing/padding of about 2.3 px. Trying on the view hierarchy, the textual content itself is a _UITextLayoutFragmentView which is inside a _UITextLayoutCanvasView. It seems that this canvas view is drawn too massive, inflicting the spacing.

The next pictures are from the view hierarchy with a one line message the place the problem seems and from a message with two strains, the place the problem just isn’t showing: https://imgur.com/a/nvrNYZM (Hyperlink since I can not publish pictures on Stackoverflow but).

What I attempted

I already set the UITextView insets with:

messageTextView.textContainerInset = .zero
messageTextView.textContainer.lineFragmentPadding = .zero
messageTextView.contentInset = .zero

which eliminated the traditional padding the UITextView has (utilizing this reply/thread).

My preliminary thought was that the messageTextView has a minimal top specified someplace, which causes the view to develop when the textual content inside (one line) doesn’t fill the minimal top. Nevertheless I do not know if thats appropriate or if there’s even a risk to vary a minimal top. Shrinking the font measurement creates a much bigger spacing.

The chat bubble makes use of UIStackViews to robotically modify its measurement to the contents. Earlier than altering to a UITextView we used an UILabel which labored high quality and didn’t create any spacing.

Has anyone skilled an analogous difficulty?

[ad_2]

Leave a Reply

Your email address will not be published. Required fields are marked *