Schriftgröße eines mehrzeiligen UILabel automatisch anpassen.
Erstellt in IPhone SDK am 30. Juni 2012
UILabel unterstützt die automatische Schriftgrößenanpassung von Haus aus. Allerdings nur bei einzeiligen Texten. Mit folgender Funktion wird die Schriftgröße an das übergebene Label angepasst:
- (void)sizeFontForLabel:(UILabel *)label { for(int i = 28; i > 10; i = i-2) { label.font = [UIFont fontWithName:label.font.fontName size:i]; CGSize constraintSize = CGSizeMake(label.frame.size.width, MAXFLOAT); CGSize labelSize = [label.text sizeWithFont:label.font constrainedToSize:constraintSize lineBreakMode:UILineBreakModeWordWrap]; if(labelSize.height <= label.frame.size.height) break; } }