Skip to content

Instantly share code, notes, and snippets.

@cmezak
Created October 16, 2013 16:26
Show Gist options
  • Save cmezak/7010710 to your computer and use it in GitHub Desktop.
Save cmezak/7010710 to your computer and use it in GitHub Desktop.
Well, I tried so many things, hoping that some of the next TextKit API would finally provide a way to precalculate the needed height for a UITextView with a given width and text. Oh well.
// HOW THE FUCK TALL DOES MY TEXT VIEW NEED TO BE?!?
@interface UITextView (WhatFuckingSize)
+ (CGSize)sizeThatFuckingFits:(CGSize)size withAttributedText:(NSAttributedString *)attributedText textContainerInsets:(UIEdgeInsets)textContainerInsets;
@end
static UITextView *FuckingTextView;
@implementation UITextView (WhatFuckingSize)
+ (CGSize)sizeThatFuckingFits:(CGSize)size withAttributedText:(NSAttributedString *)attributedText textContainerInsets:(UIEdgeInsets)textContainerInsets
{
UITextView *textView = [self FuckingTextView];
textView.attributedText = attributedText;
textView.textContainerInset = textContainerInsets;
return [textView sizeThatFits:size];
}
+ (UITextView *)FuckingTextView
{
if (FuckingTextView == nil) FuckingTextView = [UITextView new];
return FuckingTextView;
}
@end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment