Skip to content

Instantly share code, notes, and snippets.

@tiagobbraga
Last active December 28, 2015 15:19
Show Gist options
  • Select an option

  • Save tiagobbraga/7520992 to your computer and use it in GitHub Desktop.

Select an option

Save tiagobbraga/7520992 to your computer and use it in GitHub Desktop.
UITextView com altura 'Auto' ou '100%'Códigos originais em: http://stackoverflow.com/questions/50467/how-do-i-size-a-uitextview-to-its-content
// Para funcionar no iOS6
textview.scrollEnabled = NO;
- (void)textViewDidChange:(UITextView *)textView
{
CGFloat fixedWidth = textView.frame.size.width;
CGSize newSize = [textView sizeThatFits:CGSizeMake(fixedWidth, MAXFLOAT)];
CGRect newFrame = textView.frame;
newFrame.size = CGSizeMake(fmaxf(newSize.width, fixedWidth), newSize.height);
textView.frame = newFrame;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment