Skip to content

Instantly share code, notes, and snippets.

@christopherkarani
Last active November 1, 2017 09:23
Show Gist options
  • Select an option

  • Save christopherkarani/b7156d4ddee98150371446f192b49d85 to your computer and use it in GitHub Desktop.

Select an option

Save christopherkarani/b7156d4ddee98150371446f192b49d85 to your computer and use it in GitHub Desktop.
func estimatedFrame(forText text: String) -> CGRect {
// width is same as cell.texView width
//height is an arbitrary larg value
let size = CGSize(width: 200, height: 1000)
let options = NSStringDrawingOptions.usesFontLeading.union(.usesLineFragmentOrigin)
let attributes = [NSAttributedStringKey.font: UIFont.systemFont(ofSize: 16)]
return NSString(string: text).boundingRect(with: size, options: options, attributes: attributes, context: nil)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment