I am trying to give a dynamic UILabel height UILabel that my layout of the other labels looks correct in both landscape and portrait.
In the portrait, my text is wrapped in the second line, in the landscape - no. Thus, when using sizeWithFont:constrainedToSize:lineBreakMode: I get the same height when rotating in both directions when I assumed that it would be a larger number if the text was 2 lines.
How can I get the height of my UILabel when it has two lines of text or more (portrait) and get a new height, which is one line when in the landscape?
I think I donβt understand how to make dynamic height work ...
UILabel *itemTitle = [[UILabel alloc] initWithFrame:CGRectMake(10.0f, top, screen.size.width - 20, 200.0f)]; itemTitle.text = self.newsAsset.title; itemTitle.adjustsFontSizeToFitWidth = NO; itemTitle.autoresizingMask = UIViewAutoresizingFlexibleWidth; itemTitle.font = [UIFont boldSystemFontOfSize:18.0]; itemTitle.textColor = [UIColor blackColor]; itemTitle.shadowColor = [UIColor whiteColor]; itemTitle.shadowOffset = CGSizeMake(0, 1); itemTitle.backgroundColor = [UIColor blueColor]; itemTitle.lineBreakMode = UILineBreakModeWordWrap; itemTitle.numberOfLines = 0; [itemTitle sizeToFit];
source share