For the last couple of days I am trying to accomplish a fairly simple (at least it should be) layout using auto layout constraints, but without success.
My view hierarchy is:
UIScrollView
-- UIView (Container view)
-----UILabel (Multirow label)
-----UIWebView
-----UILabel
-----UIButton
The desired functionallity is the Container view to be expanding according to the size of the contents. In order to increase the height of the UIWebView I use the following code:
- (void)webViewDidFinishLoad:(UIWebView *)webView {
[self.webView sizeToFit];
}
I tried many different constraints, with the most reasonable ones being:
1. Pin top space from superview for the 1st label (Event Title)
2. Pin vertical spacing for the 1st label and the UIWebView
3. Pin vertical spacing for the rest elements (i.e. UIWebView - UILabel (Event Date) and UILabel (Event Date) - UIButton)
4. The container view has low priority (1) bottom vertical space constraint with its superview
The result I get is the following:
The UIWebView expands but does not push down the event date label and the button, plus the Container view does not expand either.
Any help would be greatly appreciated.
You may download the sample Xcode project from here.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…