UILabel text gets cut off
cocoa-touch, ios, objective-c
Solution
I have changed your method...Please check it..it may help you..
- (void) newFrame:(UILabel *) label
{
CGSize constraint = CGSizeMake(300, 1000.0f);
CGSize size_txt_overview1 = [label.text sizeWithFont:[UIFont fontWithName:@"Arial Rounded MT Bold" size:15] constrainedToSize:constraint lineBreakMode:UILineBreakModeWordWrap];
label.frame = CGRectMake(20,20, size_txt_overview1.width, size_txt_overview1.height+15);
}
Problem
I'm trying to dynamicly set label size. It works in a strange way, i get some of the text cut off. I first set my label text and then try to resize it like this way. ``` _switch2Label.text = @"Call on alarm, there will be no call if other user of alarm system will recieve an alarm call and confirm (answer) it by pressing 0#"; _switch2Label.numberOfLines = 0; [self newFrame:_switch2Label]; - (void) newFrame:(UILabel *) label { CGSize maxSize = self.view.bounds.size; maxSize.width = maxSize.width - 30; CGSize labelSize = [label.text sizeWithFont:label.font constrainedToSize:maxSize lineBreakMode:label.lineBreakMode]; CGRect newFrame = label.frame; newFrame.size.height = labelSize.height; label.frame = newFrame; } ``` I only get three lines of text, while five is needed for this label. Maybe anyone could see my mistake here? If I add more text to label it gets shown, yet still about two lines of the label text gets cutt off.