UILabel text is disabled

I am trying to dynamically set the label size. This works in a weird way, I turned off some of the text. I first set my shortcut text and then try to change it 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 get only three lines of text, and this shortcut requires five. Maybe someone could see my mistake here? If I add more text for the label, it will be shown, but still about two lines of label text will be disabled.

+4
source share
4 answers

I changed your method ... Please check it .. this can 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); } 
+2
source
  _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 maximumSize = CGSizeMake(label.frame.size.width, 10000); //maxSize.width = maxSize.width - 30; CGSize labelSize = [label.text sizeWithFont:label.font constrainedToSize:maximumSize lineBreakMode:UILineBreakModeWordWrap]; CGRect newFrame = label.frame; newFrame.size.height = labelSize.height; label.frame = newFrame; } 

Use these code blocks, u can help.

+2
source

Why change the label size? Is this something you cannot do in IB or autorezizeMask ?

0
source

The label restriction size is not calculated as you intend, currently your code limits the label height to the label height. Modifying a maxSize instance for:

 CGSize maxSize = CGSizeMake(self.view.bounds.size.width - 30, MAXFLOAT); CGSize labelSize = ... 

Doing this ensures that the constraint is not bound by the boundaries of your view. You can also consider setting the clipToBounds property of your view if you want the shortcut to skip the borders of your view.

0
source

All Articles