UITextView auto resizes to fit a UITableViewCell

Derrick Ho
1 min readJul 31, 2016

You ever add a UITextView to one of your UITableViewCell’s? I have done it quite a few times due to some limitations of UILabel. But here is the problem: The UITextView is a UIScrollView. I had believed that it had no content size. Unlike UILabel which can determine its content size, the UITextView can not, or so I thought. The UITextView looks like it shouldn’t have a content size, but if you disable scrolling, it will resize when putting it in a UITableViewCell. I suppose when it has no scrolling, it is basically a UILabel in terms of functionality.

To prove this hypothesis, I have put together a small project to prove that this works.

https://github.com/wh1pch81n/TableViewtextViewExperiment.git

This actually surprised me because I thought I would have to use sizeThatfits(_: CGSize) in order to get the intended height and then add a height constraint to the UITextView.

Sign up to discover human stories that deepen your understanding of the world.

Free

Distraction-free reading. No ads.

Organize your knowledge with lists and highlights.

Tell your story. Find your audience.

Membership

Read member-only stories

Support writers you read most

Earn money for your writing

Listen to audio narrations

Read offline with the Medium app

No responses yet

Write a response