Reputation: 61
I've a screen in an app I'm coding structured like this:
View
ScrollView
View
label 1
label 2
label 3
View
UIImageView
WebView
When loaded it adds some html string into the Web View and as the whole content (labels,image,html content) is longer than the screen height, I would like to allow the screen to scroll down/up when user is reading content. This is why I added the SrollView but nothing scroll!
I also did is scroll_view.contentSize = [self.view bounds].size;
but it didn't work
Any idea on how to do this ?
Thx in advance for helping,
Stephane
Upvotes: 0
Views: 428
Reputation: 967
Below code u observe Here "Height" declare Dynamically as your Requirement
EXample :
if([Myarray length]>25)
{
myString = [myString stringByAppendingFormat:@"<tr><th align=\"left\">%@</tr>",str_owes ];
height += 50;
}
webview.frame=CGRectMake(25, 153, 420, height);
[webview loadHTMLString:myString baseURL:nil];
scrollview.contentSize=CGSizeMake(0, webview.frame.origin.y+webview.frame.size.height+50);
Upvotes: 1
Reputation: 51374
By default UIScrollView is set a contentSize
equal to its frame
size. If you want it to be scrollable, you have to explicitly set the contentSize.
scrollView.contentSize = CGSizeMake(_width, _height);
Mostly you won't be knowing the actual contents size while you create the scroll view. You can assign the contentSize after adding the UIWebview(as web view is the last view in your scroll view). You can do it like this,
// Add other views to scrollView
// Create and configure webView
[scrollView addSubview:webView];
float _width = scrollView.contentSize.width; // No change in width
float _height = CGRectGetMaxY(webView); // Returns (webView.frame.origin.y + webView.frame.size.height)
scrollView.contentSize = CGSizeMake(_width, _height);
Upvotes: 2
Reputation: 15376
You need to set the UIScrollView
's contentSize
to be the size of the two views + the UIWebView combined.
You will also need to make sure that the UIWebView
if of the right size and then turn scrolling off, as you may get scrolling issues otherwise (one scroll view inside another).
Upvotes: 0