Set UILabel to zero height if label is empty / storyboard

I have many shortcuts superimposed on the contact information screen. If any of the labels is empty, I would like to reset their height and not take up space in order to avoid empty space on the screen. However, I created the screen in the storyboard, and the labels were assigned the values ​​of height and y.

Here is the code that I tried to use to change the height of the inscription, but I can not get it to work. Perhaps it is designed to work only for created programs, and the storyboard settings override what I'm doing here.

NSString *string = @"some text"; 
CGSize maximumLabelSize = CGSizeMake(280,1000);
 
// use font information from the UILabel to calculate the size
CGSize expectedLabelSize = [string sizeWithFont:myLabel.font constrainedToSize:maximumLabelSize lineBreakMode:NSLineBreakByWordWrapping];
 
// create a frame that is filled with the UILabel frame data
CGRect newFrame = myLabel.frame;

// resizing the frame to calculated size
newFrame.size.height = expectedLabelSize.height;

// put calculated frame into UILabel frame
myLabel.frame = newFrame;

Is there a way to get the height of labels created in the storyboard to zero if they are empty?

+4
2

, , - :

-(void) layoutSubviews {
    myLabel.frame = CGRectZero;
}

, . . . , . , CGRectZero.

0

Source: https://habr.com/ru/post/1622740/


All Articles