How to Zoom UIWebView in iPhone - iphone

I am new to this technology,
I am loading webpage in my webview,
I didn't set scalePageToFit property. without using this property i want to do Zooming In and Out on my webview.
is it Possible ?
Here is my Code snippet,
NSURL *url2=[NSURL URLWithString:str1];
NSURLRequest *req2=[NSURLRequest requestWithURL:url2];
[webView1 loadRequest:req2];
[webView1.scrollView setZoomScale:2.0 animated:TRUE];
[webView1 release];
str1 is my url i tried this but, still i am unable to zoom my web view in simulator.
Any help will be appreciated.
Thanks In Advance !

UIWebView is having scrollView as a property. Use ScrollView's delegate method
– scrollViewDidEndZooming:withView:atScale:
This might help you.
Follow this link : This might give you some clue. how to zoom the scrollview.

You need to set scalePageToFit property to YES.

Related

Webview content not resizing

I have a webview.. with the following attributes:
1.scalesPageToFit
2.Autoresizing masks
3.contentmode = aspectFit
After loading it fits to the page as obvious. But as soon as i zoom in and then zoom out to normal; rotating the device doesn't fit completely.
As a tweak, i have checked if the orientation mode is landscape reload the web page. I read various posts in this regard, but couldn't find any solution.
You have 2 folowing options:
Add this into head section of your html file:
<meta name="viewport" content="width=device-width" />
Or call [myWebView reload] when orientation changes
You can use this Code
NSString *website =#"http://www.google.com";
NSURL *url = [NSURL URLWithString:website];
NSURLRequest *requestURL =[NSURLRequest requestWithURL:url];
mywebview.scalesPageToFit = YES;
mywebview.autoresizesSubviews = YES;
[mywebview loadRequest:requestURL];
It took more than 2 days to find out the reason causing this issue. Actually webview was working correctly except the fact that if you try to use PinchGesture to zoom out further.. webview will baheve in the same way.
To overcome this issue, we need to set the zoom scale of scroll view in Webview under willRotate method. However, it's animating weirdly but one can make a guess where the issue lies.

IOS how to reload a webview

Some help please,
I am putting a web app together and I am stuck on a few things.
I have tabviewcontrollers which load different uiwebviews.
Each time I navigate on the app and re-click the tab it remains where I was on that page is there a way to re-load it so it always goes from the orginal ur (not just a refresh)?
Any advice on the best way to handle this would be appreciated.
Thank you
Steve
Load the request in your view controller's viewWillAppear: method.
When you want to refresh, use
[webView reload]
or for if you want t reload with a specific url
NSURL *theURL = [NSURL URLWithString:#"http://urltoreload.html"];
[webView loadRequest:[NSURLRequest requestWithURL:theURL]];

how to detect any Link in HTMLString in webView? (Iphone)

if i want that i can detect the link appeared in my HTMLstring in webView...how can I do it?
I know in IB As we checkmark the box of auto detectable link... but I want to know programatically
Did you check the dataDetectorTypes property?
For example use this:
[[self content] setDataDetectorTypes: UIDataDetectorTypeAll];
You could use:
UIDataDetectorTypePhoneNumber
UIDataDetectorTypeLink
UIDataDetectorTypeAddress
UIDataDetectorTypeCalendarEvent
UIDataDetectorTypeNone
UIDataDetectorTypeAll
Reference-Link UIWebView

Allowing user to pinch zoom in/out of a webview

I have a WebView into which I'm loading a local HTML page with some embedded images. I want to allow the user to zoom in on the text and image in a similar fashion as they would with the web browser.
Any ideas how to enable this?
Thanks
Try to set UIWebView property scalesPageToFit to YES
For completeness. You must enable multitouch, scalesPagesToFit to get it to work (there are some conditions if its within certain other views).
But then to prevent it scaling your webpage (especially if using local files). You will need to add the following snippet to your HTML
For more info so: http://iphoneincubator.com/blog/windows-views/right-scale-for-a-uiwebview
This is the code that works for me:
// declare and allocate UIWebView before
// UIWebView *webView;
// webView = [[UIWebView alloc] initWithFrame:CGRectMake(x, y, w, h)];
webView.scalesPageToFit = YES;
I used scalesPageToFit to YES.... it allows it to zoom in some... but not a true zoom like safari has.

iPhone - Is it possible to hide native scrollbar in UIWebView?

I would like to hide the native scrollbar / scroller that appears when you are scrolling a UIWebView, but still keep the scrolling functionality intact. Is this possible?
Thanks in advance,
William
It seems this question needs an updated answer:
You can directly access the scroll view associated with the web view. (read-only)
in iOS 5.0 an above.
I don't think developers should be supporting anything prior to iOS 5.0 unless in exceptional circumstances.
From the Apple developer docs.
#property(nonatomic, readonly, retain) UIScrollView *scrollView
Discussion
Your application can access the scroll view if it wants to customize the scrolling behavior of the web view.
Availability
Available in iOS 5.0 and later.
Declared In
UIWebView.h
Now you can directly write something like this:
webView.scrollView.showsHorizontalScrollIndicator = NO;
webView.scrollView.showsVerticalScrollIndicator = NO;
No need to go to the subviews of the webView.
UIWebView doesn't inherit directly from UIScrollView, but you may be able to use UIScrollView properties on the UIWebView subview:
[(UIScrollView*)[webview.subviews objectAtIndex:0] setShowsHorizontalScrollIndicator:NO];
[(UIScrollView*)[webview.subviews objectAtIndex:0] setShowsVerticalScrollIndicator:NO];
No idea if this is acceptable, but it builds okay and I think it should work. Please report back if this works for you.
Also consider filing a feature request to Apple at bugreport.apple.com to add this property to a future UIWebView implementation.
Do it in that way:
for (id subview in self.myWebView.subviews) {
if ([[subview class] isSubclassOfClass: [UIScrollView class]]) {
((UIScrollView *)subview).bounces = NO;
((UIScrollView *)subview).showsVerticalScrollIndicator = NO;
((UIScrollView *)subview).showsHorizontalScrollIndicator = NO;
}
}
In Swift :
webView.scrollView.showsHorizontalScrollIndicator = false
webView.scrollView.showsVerticalScrollIndicator = false
If someone is looking for swift solution then below is the code for swift 3.0
yourWebView.scrollView.showsHorizontalScrollIndicator = false
yourWebView.scrollView.showsVerticalScrollIndicator = false
There's seems to be the beginning of an answer here :
http://discussions.apple.com/thread.jspa?threadID=1781730
If you disable user interaction, this seems to remove the scrollbar (this may be ok if the web page you display does not exceed the screen height).
A kind of javascript hack seems to be described also but I'm not mastering it :/ (you need to have access to the web page you try to display however, and this may not be your case....)