views:

224

answers:

2

I have had to change a UIScrollView into a UIWebView due to formatting reasons.

There is a problem though that I need to be able to get the content offset back to 0, 0 (as I am using reusable UIWebViews and changing content) and get the content size so I can place a button at the bottom; but UIWebView does not seem to have this.

+1  A: 

Use JavaScript.

I think that the next line should do the magic:

[webView stringByEvaluatingJavaScriptFromString:@"window.scroll(0,0)"];
Michael Kessler
Ill give that a try. What about getting content height so i can add a button at the bottom of the UIWebView?
jodm
Hmmm. This one is more complicated. I believe it is possible. I suppose that you have to take in account the height of the webView, the height of the HTML (by using JavaScript) and the current zoom level. Or, you might disable the zoom (if not done so yet) and then it will be much simpler. Just locate your button so that its bottom will be few pixels above the height of the webView. you should locate it above the HTML by using style/CSS (google for "css floating div").
Michael Kessler
By the way, you might locate an Objective-C button (UIButton) above the web view. This way you you won't need to learn CSS or JavaScript at all...
Michael Kessler
See the solution I did above. Seems to be working just got a few tweaks and then should be fine... :o) Cheers for your help.
jodm
+1  A: 

The best way I found to sort the problem was:

  1. Create a UIWebView
  2. Put it in a UIScrollView
  3. Add the HTML into it using "loadHTMLString"
  4. Using the "- (void)webViewDidFinishLoad:(UIWebView *)webView {" delegate method I detect the size of the UIWebView

  5. Set the frame of the UIWebView to the content size.

  6. Remove interaction from the UIWebView
  7. Set the Content size of the UIScrollView to the content size.

Then used the functionality of the UIScrollView instead of the UIWebView.

Thanks -JM

jodm