Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set content offset and content size in a UIWebView

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.

like image 308
jodm Avatar asked Aug 19 '10 19:08

jodm


2 Answers

This problem can be solved quite easily:

[[webView scrollView] setContentInset:UIEdgeInsetsMake(64, 0, 44, 0)];

Remember that UIEdgeInset is different from CGRect!
A guide on UIEdgeInset can be found in the iOS Developer Library.

like image 57
BaviDaan Avatar answered Oct 22 '22 18:10

BaviDaan


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

like image 40
jodm Avatar answered Oct 22 '22 17:10

jodm