Siu Chung Chan
Siu Chung Chan

Reputation: 1686

UITextView last line is not shown

I got an UITextView with content: A A A

and here it is, as I see there are lots of spacing below the last line, so I reduce the TextView height by few pixels.

enter image description here

and the last 'A' disappear, and there is obviously lots of spacing for the letter 'A', any idea?

Upvotes: 3

Views: 1490

Answers (3)

Burro
Burro

Reputation: 63

I think it's the content size of UITextView is not correct. I faced the same issue when I disable edit or select. And the log tells the width of content size was 0, and the height was not correct as well. Try:

textView.contentSize = textView.sizeThatFits(textView.frame.size)

That works for me anyway.

Upvotes: 1

Nguyen Hoan
Nguyen Hoan

Reputation: 1693

i think reason is height of textview not enough for inset of textview and lint padding. Try:

    self.textView.textContainerInset = UIEdgeInsetsZero
    self.textView.textContainer.lineFragmentPadding = 0

Upvotes: 5

Amin Negm-Awad
Amin Negm-Awad

Reputation: 16660

Likely the space is too small to draw every possible character available in Unicode and the font (esp. those with descender) so the layout machinery does not layout the whole line, even there would be enough space for the A. If they do not so, changing of the text could potentially hide and unhide the last line, what would be puzzling.

If you are really sure that there is no such problem, you could embed the text view in a superview, clipping the text view.

Upvotes: 0

Related Questions