Goal:
Have a UIWebView
be the same width as it's superview, which is a UIScrollView
, using autolayout constraints.
Code
NSLayoutConstraint *makeWidthTheSameAsScrollView =[NSLayoutConstraint
constraintWithItem:self.questionWebView
attribute:NSLayoutAttributeWidth
relatedBy:0
toItem:self.masterScrollView
attribute:NSLayoutAttributeWidth
multiplier:1.0
constant:0];
[self.view addConstraint:makeWidthTheSameAsScrollView];
NSLog(@"The width of questionWebView *AFTER* adding the constrain is: %f", self.questionWebView.frame.size.width);
NSLog(@"The width of scrollView *AFTER* adding the constrain is: %f", self.masterScrollView.frame.size.width);
Current Result
When I log the width of self.questionWebView
(the UIWebView
), it's width does not change when the autolayout constrain is applied.
Questions
- Is this the correct approach?
- What am I doing wrong?
p.s I know it is against Apple's recommendations to place a UIWebView
in a UIScrollView
, however I've turned off the ability to scroll the UIWebView
using the property self.questionWebView.userInteractionEnabled = NO;
. And currently using a UIWebView is my best strategy for displaying an HTML table.