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

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.

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

Resize by default TinyMCE

I'm using TinyMCE for the first time, and I love it, but is a bit closed.
I'd like to get images resized by default, this is, when adding an image, put it by default on 300px width, for example (then the user can make it bigger or smaller dragging).
I don't know where to touch! Is there a command within the lists of images (the js you can attach to make TinyMCE show a list of images)? Or I have to hack css? Or I have to dive into TinyMCE code?
Thank you in advance
Marc
If you are OK with changing code files then proceed as follows
Open tiny_mce/plugins/advimage/js/image.js
Locate insertAndClose : function()
Insert after
var ed = tinyMCEPopup.editor, ......;
if(f.width.value == ""){
f.width.value = 300;
}
Hope it helps!
There are several options. I would go the css way. Check out the tinycme init configuration setting content_css. Using an additioanl own css file enables you to setthe width of images to 300px easily.

How to apply local styles / JS to UIWebview after loading a URL

I am loading a web page in my iPhone app. However the page is not mobile optimized. So, I would like to customize some elements from the page like remove sidebar etc.
For doing this, I guess, some CSS / JS need to be injected into the page to modify the page. Can this be done ? If yes, how to?
Any help appreciated.
For others having same question:
It can be done by using stringByEvaluatingJavaScriptFromString: method of UIWebView (upon webViewDidFinishLoad)
-(void)webViewDidFinishLoad:(UIWebView *)webView {
[webView stringByEvaluatingJavaScriptFromString:#"document.getElementById('topBarBody').remove();"];
}

uiwebview Zoom in Not working perfectly

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.

text and image as one scrollable entity

I need an undefined amount of text and one or more pictures to be scrollable as one entity. I'm quite surprised that this doesn't seem to be provided by default, I thought I've seen that several times before... I tried to google, but all I find doesn't fit. The images won't be wider than the screen, but in between lines of text.
I need something that let's me do something like:
image
textA
textA goes on
__ screen ends here, content goes on
textA goes on
textA goes on
image
image
textB
textB goes on
image
textC
The content for the text would come out of a plist, but I THINK I can predict it will be REALLY static, so I could just set the Text in IB and create a view for every content -.-.
I've read about Web View, but as far as I got it, you'd need internet connection to make that work, and the app should work without any internet connection at all.
Any suggestions or experiences concerning that?
Thanks a lot!
There different way to get things done:
If you have static content and want a complicated layout and know how to do it in html you should go with UIWebview and a bundled html file and images and load it with something like:[webView loadRequest:[NSURLRequest requestWithURL:[NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:#"MyStuff" ofType:#"html"]]]];
You can also do a layout with UILabels and UIImageviews and arrange all of this onto one UIScrollview
If it's more dynamic you should go with the latter, but you need to program sort of layout algorithms that handle different number/sizes of images, number/length of test paragraphs and so on.
One option, as you mention, is UIWebView.
It does not require a connection, since you can load a static HTML into it executing:
– loadHTMLString:baseURL:
By specifying a baseURL that "points" to your bundle, you can also include images as resources in your Xcode project and have them displayed (by using <img src=... /img in your HTML):
NSString* basePath = [[NSBundle mainBundle] bundlePath];
[_label loadHTMLString:text baseURL:[NSURL fileURLWithPath:basePath]];
You don't need an internet connection to make a web view work. Look at this method on UIWebView:
- (void)loadHTMLString:(NSString *)string baseURL:(NSURL *)baseURL