Skip to content

Instantly share code, notes, and snippets.

@zbowling
Created May 3, 2012 23:26
Show Gist options
  • Save zbowling/2590376 to your computer and use it in GitHub Desktop.
Save zbowling/2590376 to your computer and use it in GitHub Desktop.
// HACK: Create an offscreen text view solely for calculating the height of table view cells
// containing text views. This bizarre hack is needed because:
//
// a.) UITextView is bizarre and uses WebKit instead of UIKit's methods for displaying strings,
// and NSString's sizeWithFont:constrainedToSize: does not calculate the height exactly as
// it does. (For instance, the height of strings with trailing whitespace are calculated
// differently, and UITextView some strange built-in padding and slightly
// different-than-usual line height that is annoyingly difficult to replicate, etc...,
// etc...).
//
// b.) If a UITextView has not been added to a view heirarchy, its contentSize property will...
// always... just be equal to the frame. In addition, desperately attempting to add it as a
// subview of another UIView, or even a UIWindow, which is also not a part of a parent's
// heirarchy does not seem to fix this, which means we have to sadly break separation of
// concerns and stuff it in here.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment