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
Related
I want to display Xml file on UIWebView, what i am doing is this:
[m_WebView loadData:[NSData dataWithContentsOfURL:theURL] MIMEType:nil textEncodingName:nil baseURL:nil];
But this is not displaying it properly and i have no control over the color components of it, any suggestions!
You need to use your own style sheet to enable control on component, else web view loads xml as its default format.
Check out following tutorial on css with UIWebView - http://mentormate.com/blog/iphone-uiwebview-class-local-css-javascript-resources/, http://iphoneincubator.com/blog/windows-views/uiwebview-revisited
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.
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.
I have an app that I'm trying to allow users to choose which youTube movie they play. I have a UIWebView with an embedded url, but I want that embedded code to able to change.
So far, I can't get this to change. This current setup only shows a blank white screen. When I put youtubeURL in place of the # it works fine, but not changeable. Any ideas how to change the URL? I have it setup so they can type a url that gets saved as youtubeURL, and that is the URL I want the UIWebView to show.
In my viewDidLoad:
youtubeURL = #"http://www.youtube.com/watch?v=HQ7R_buZPSo";
In my playMovie triggered by a button:
NSString* html = [NSString stringWithFormat:#"\
<html><head>\
</head><body style=\"margin:0\">\
<embed id=\"yt\" src=\" %# \" type=\"application/x-shockwave-flash\"\
width=\"1024\" height=\"748\"></embed>\
</body></html>", youtubeURL];
[self.view addSubview:youTubeView];
[youTubeView loadHTMLString:html baseURL:nil];
...
Thanks in advance!
So this started working randomly. I understand the fact that the user can't change the code, which is why I had youtubeURL to allow them to change the youtube link. I just had them type whatever they wanted into a UITextField, and saved it to a label as well as to youtubeURL. Works just fine now.
You'd have to have an input text box and then do youtubeURL = inputLabel.text (or just skip the youtubeURL variable altogether.
You can't have the user change the code.
I want to embed a google calendar into an iphone app, my webview is fine, except I can't seem to get the URL I need to view the mobile version without having to logging in.
I know its possible as this is done in the twit app (See Screenshot below).
How can I do this?
Lets say the public google calendar is link text and I want to view the Mobile version of this page in a UIView.
The mobile view is available at link text, but you must first be logged into a google account.
Help Stackoverflow!
alt text http://posterous.com/getfile/files.posterous.com/norskben/RtIkoblEW9VsBE07dAQy9Sjjo4aRL2yjCRTCIx316y7ovsCXo9iKeGLL1AMx/photo.jpg
All under control now. Although I didn't find it possible to access the gp mobile view, it turned out infact to be just the agenda view of the normal view.
NSString *gcal = [NSString stringWithFormat:#"<html><meta name=\"viewport\" content=\"width=320\"/><iframe src=\"http://www.google.com/calendar/embed?showTitle=0&showNav=0&showTabs=0&showPrint=0&showCalendars=0&mode=AGENDA&height=600&wkst=2&hl=en_GB&src=northadelaidefitness#gmail.com&color=%23A32929&ctz=Australia%2FAdelaide\" style=\"border-width: 0pt;\" mce_style=\" border-width:0 \" frameborder=\"0\" height=\"400\" width=\"300\"></iframe>"];
[webview loadHTMLString:gcal baseURL:nil]; //load above html string (notice the viewport=320 for iphone resizing
webview.delegate = self; //add delegate for activity access
webview.scalesPageToFit =YES; //scale nicely