-
-
Save darkseed/1159594 to your computer and use it in GitHub Desktop.
How to make a multiline label with dynamic text on the iphone and get the correct height
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
UILabel *myLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 320, 9999)]; | |
myLabel.lineBreakMode = UILineBreakModeWordWrap; | |
myLabel.numberOfLines = 0; | |
myLabel.text = @"Some \n dynamic \n multiline \n text"; | |
[myLabel sizeToFit]; // This shrinks the 9999 down to the size of the text | |
NSLog(@"Actual height is: %f", myLabel.frame.size.height); // Use this for spacing any further elements | |
[self.view addSubview:title]; // Or add it to a scroll view, or whatever... | |
[myLabel release]; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment