KnowledgeHub
Questions
Tags
Users
Search
Alex Rivera
|
Logout
Edit Question
Title
Body
Here is my code UILabel *label = [[UILabel alloc]initWithFrame:CGRectMake(10, 50, 300, 50)]; label.textAlignment = UITextAlignmentCenter; label.backgroundColor = [UIColor clearColor]; label.textColor = [UIColor whiteColor]; label.textColor.font = [UIFont fontWithName:@"Verdana" size:30]; label.text = @"A very long string"; etc... The problems is that the font is large and can't fit in the label. It just display "A very" What to do so entire text to be displayed. I have tried label.lineBreakMode = UILineBreakModeWordWrap; label.numberOfLines = 0; But it doesn't work for me. I want to do that programmatically. //EDIT CGRect frame = CGRectMake(10, 50, 300, 50); NSString *labelString = @"Players."; UILabel *howManyUsersLabel = [[UILabel alloc]initWithFrame:frame]; howManyUsersLabel.textAlignment = UITextAlignmentCenter; howManyUsersLabel.backgroundColor = [UIColor clearColor]; howManyUsersLabel.textColor = [UIColor whiteColor]; howManyUsersLabel.adjustsFontSizeToFitWidth = NO; howManyUsersLabel.numberOfLines = 0; CGFloat fontSize = 30; while (fontSize > 0.0) { CGSize size = [labelString sizeWithFont:[UIFont fontWithName:@"Verdana" size:fontSize] constrainedToSize:CGSizeMake(frame.size.width, 10000) lineBreakMode:UILineBreakModeWordWrap]; if (size.height <= frame.size.height) break; fontSize -= 1.0; NSLog(@"test"); } howManyUsersLabel.font = [UIFont fontWithName:@"Verdana" size:fontSize];
Tags (comma-separated)
Save Edits
Cancel