Created
July 4, 2016 11:51
-
-
Save JigarM/559930b18c34ef730e9a2af142b1436e to your computer and use it in GitHub Desktop.
Objective-C Auto Set Height of UITextView Raw
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// leave the width at 300 otherwise the height wont measure correctly | |
UITextView *textView = [[UITextView alloc] initWithFrame:CGRectMake(10.0f, 0.0f, 300.0f, 100.0f)]; | |
// add text to the UITextView first so we know what size to make it | |
textView.text = [_dictSelected objectForKey:@"body"]; | |
// get the size of the UITextView based on what it would be with the text | |
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