uiwebview Zoom in Not working perfectly - iphone

I have zoom my webview using the following code on the button click event
[webView_ stringByEvaluatingJavaScriptFromString:#"document.body.style.zoom = 5.0;"];
really the webview zoom when i am click that button after few second again webview comes normal state.
Pls help me how to maintain that zoom without resize...
Thanks in advance,
Suresh.M.

Just add this to your html document head
<meta name='viewport' content='initial-scale=5.0'/>
Also, do
[webView_ setScalesPageToFit:YES];
as iPhoneiPadDev stated, if you want the webview to also allow zooming to different zoom level
cheers

try to use this.
[webView_ setScalesPageToFit:YES];
This will help you.

Related

Pinch To Zoom in UIWebView in iphone App

I am Developing simple App. I am accessing html pages on UIWebVIew. and I wanted to zoom that html pages with the help of zoom option
please help me out.
Zooming IN, OUT and Pinch are Built In feature of UIWebView. You don't need to write any code to achieve that.
Simply , Use your fingers.
On Simulator , you can use Option (Alt) and Shift Keys with Mouse.
Make your option Scale Page to Fit ON.
Try this below property
webView.scalesPageToFit = YES;
First of all set this property given below:
webView.scalesPageToFit = YES;
Then you have to set view port on meta data on the html string. In my case head tag was empty. Thats why I just replaced head with the with head containing meta tag.
htmlString = [htmlString stringByReplacingOccurrencesOfString:#"<head></head>"
withString:#"<head><meta name=\"viewport\" content=\"width=568\"/></head>"];
[webView loadHTMLString:htmlString baseURL:nil];
Using Storyboard :
There is built-in property of WebView ‘Scales Page To Fit’ which is false by default.
Select WebView -> Open Utilities Window -> Goto Attribute Inspector’
Set ‘Scales Page To Fit’ to true (Checkmark it)
Programmatically :
objWebView.scalesPageToFit = true

UIWebView set initial zoom scale programmatically when loading an external website?

What I want to do is set the initial zoom scale [and in some cases, content offset, but that is less important] for an external website. But after the app initially sets the zoom and offset, the user should be able to change them, and the app should not interfere.
Some related information is available here, here, and here. But as far as I can tell, none of does what I want.
The meta setting approach looks promising -- but how would I set it when I don't control the html content that will be loaded?
Try this for setting the initial zoom level -
[webView stringByEvaluatingJavaScriptFromString:#"document. body.style.zoom = 5.0;"];
Also dont forget to set scalesPageToFit to NO and you're done.
If you set this to YES, the webpage is scaled to fit and the user can zoom in and zoom out. If NO, user zooming is disabled. The default value is NO.
If you want to set initial zoom for your web view and then your web view can scaleable. You can try to add meta tag into the head tag of your HTML string at webViewDidFinishLoad protocol method. You can change 'initial-scale', 'minimum-scale'and 'maximum-scale' to adapt to your required. Looks like this:
- (void)webViewDidFinishLoad:(UIWebView *)webView {
NSString* js =
#"var meta = document.createElement('meta'); " \
"meta.setAttribute( 'name', 'viewport' ); " \
"meta.setAttribute( 'content', 'width = device-width, initial-scale = 1.0,minimum-scale=1.0,maximum-scale=10.0 user-scalable = yes' ); " \
"document.getElementsByTagName('head')[0].appendChild(meta)";
[webView stringByEvaluatingJavaScriptFromString: js];
}
Why not:
[self.webView.scrollView setZoomScale:2.0 animated:YES];
best one found try adding meta tag in your html page,in your tag.It gets repaired in a eye blink.
Try the apple link and select the suitable meta tag for you.
if you are loading html and javascriptin uiwebview then in viewport set user-scalable=1.0.

Easiest Way To Add In-App Internet Browser?

I'm looking at how to make a very simple browser in my app. Only need reload, back, forward, etc.
Does anyone have any simple code they can add here?
I have a tableviewcell that when clicked will launch this view.
Add a UIWebView.
You can use
[webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:#"http://www.google.com"]]]`
to open a website, -reload to reload, – goBack and -goForward to go back or forward.
Check out the UIWebView API, which is basically a WebKit rendering widget - the one that also powers iPhone's browser app.

iPhone XCODE Programming make a UIWebView Scrollable

here is the problem! I have a UIWebView in my programs that loads a php page.
The problem is that if the page has a lot of lines i cannot see them.
I can "scroll" the UIWebView but when I leave the finger from the screen the page comes back to the original state.
I don't want to scale pages to fit the view cause if I do that the letters become too small.
I would like to find a way to scroll pages how it is possible in Safari.
Hope i have explained the problem.
Thank you in advance
Antonio
If you have control of the web page, it is easier to control the UIWebView with http than programmatically.
<meta name="viewport" content="width=device-width; initial-scale=1.0; maximum-scale=1.0; minimum-scale=1.0; user-scalable=0;" />
<meta name="apple-mobile-web-app-capable" content="yes" />
I would recommend applying the following:
Set scalesPageToFit=YES before the UIWebView gets loaded. I know you don't particularly want to scale the whole thing - but once you can scroll and zoom then having a macro view can be a good starting point.
Set the bounce behavior, within
- (void)webViewDidFinishLoad:(UIWebView *)theWebView {
//turn multi touch on for theWebView!!!
theWebView.multipleTouchEnabled = YES;
//control bounces and bounesZoom for the boundary
[[theWebView.subviews objectAtIndex:0] setBounces:YES];
[[theWebView.subviews objectAtIndex:0] setBouncesZoom:NO];
....
These two things did the job for me.
You should have a look at the scalesPageToFit-Property of the UIWebView.
http://developer.apple.com/iphone/library/documentation/UIKit/Reference/UIWebView_Class/Reference/Reference.html#//apple_ref/occ/instp/UIWebView/scalesPageToFit
you can always use
UIWebView *wv = [controller webbrowser];
[wv loadHTMLString:pageUrlToLoad baseURL:nil];
wv.scalesPageToFit = YES;
It does the trick for me.
it will try to fit the entire page in the window.
ADD ON:
write UIWebView in XCode window and pressing the ALT key, double click on it.
it will show the Fast Help window, there you can find projects using that View
click on UI Catalog and when it opens, click the button Open with XCode
select the folder you want to have all the project files and go
select the iPhone Simulator 3.1.3 as the target device and Run the app.
You will get a lot of User Interfaces and all the code they use is right there so you can copy/paste and change to your own way.
give it a shoot!

Remove html tags from UIWebView

I am developing an application for iphone which needs to load some description to a UIWebView. But text that loads into the UIWebView shows some html tags like <p></p>.Is there any way to remove these type of tags?
Thanks in advance
I asked a similar question the other day and got some good responses. I imagine one of these could suit your needs.
anyway to delete all <a href=> tags with javascript after the page loads on an iPad?
Hope it is helpful!
This is the best answer and is exactly what you are looking for ...
Write the following script in the webView delegate method. ( UIWebviewdidfinishLoading)
NSString *myText = [webView stringByEvaluatingJavaScriptFromString:#"document.documentElement.textContent"];