Skip to content

Instantly share code, notes, and snippets.

@CreatureSurvive
Forked from fethica/UITextView.m
Created October 26, 2018 01:06
Show Gist options
  • Save CreatureSurvive/6af1476328d0ad6cad7e7752057aebf7 to your computer and use it in GitHub Desktop.
Save CreatureSurvive/6af1476328d0ad6cad7e7752057aebf7 to your computer and use it in GitHub Desktop.
Size-to-Fit Text in UITextView
#define kDefaultFontSize 24.0
myTextView.text = @"Some long string that will be in the UITextView";
myTextView.font = [UIFont systemFontOfSize:kDefaultFontSize];
//setup text resizing check here
if (myTextView.contentSize.height > myTextView.frame.size.height) {
int fontIncrement = 1;
while (myTextView.contentSize.height > myTextView.frame.size.height) {
myTextView.font = [UIFont systemFontOfSize:kDefaultFontSize-fontIncrement];
fontIncrement++;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment