Please review this easy example of dynamic multiline UILabel
with Autolayout that should force its superview to grow in height. The example is working fine in portrait orientation, while in landscape the UILabel
grows too much in height.
I set constraints in storyboard, vertical compression and hugging priority of the label is 1000, the superview's is 1. All other top, bottom, leading and trailing constraints inbetween views are standard.
I have colored the background of the label with very lightgray color so it is clear that the label's top and bottom margins are much bigger than in portrait mode. Can somebody please advise how can I get the label with same top and bottom margins in landscape as well? Thanks.
- (void)viewDidLoad
{
[super viewDidLoad];
self.myTextLabel.text = @"iPhone 6 rumoured to have larger display.";
}
- (IBAction)button:(UIButton *)sender
{
if (!self.flag) {
self.innerHeightConstraint.constant = 120.0;
self.myTextLabel.text = @"iPhone 6 rumoured to have larger, 1704 x 960 display. A new report indicates that Apple's testing it.";
self.flag = YES;
} else {
self.innerHeightConstraint.constant = 60.0;
self.myTextLabel.text = @"iPhone 6 rumoured to have larger display.";
self.flag = NO;
}
[self.view layoutIfNeeded];
}