Adding HTML file in xcode as UIWebView - iphone

When I add an HTML file in UIWebView I am not getting the ful size image. only a quarter of the image is getting displayed. my code is
-(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
[webview loadRequest:[NSURLRequest requestWithURL:[NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:#"Ganesh" ofType:#"html"]isDirectory:NO]]];
webview.delegate=self;
}
The image is displayed as upside down. Can any one help me to fix this?

webView.backgroundColor=[UIColor colorWithRed:153.0/255 green:22.0/255 blue:11.0/255 alpha:1.0];
NSURL *url = [NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:#"faq-1" ofType:#"html"]isDirectory:NO ];
NSURLRequest *requestObj = [NSURLRequest requestWithURL:url];
[webView loadRequest:requestObj];

set the frame of webview according to the orientation.

Related

Passing NSString to Webview

I have an NSString called status and I am trying to pass that variable to load a webView. The app is crashing here, but I don't know what I am doing wrong? Does anyone see anything wrong with the request?
[webView loadRequest:[NSURLRequest requestWithURL:[NSString
stringWithFormat:#"http://www.website.com/page.php?status=%#", status]]];
requestWithURL accepts NSURL, So you need to convert string into NSURL
Try this,
[webview loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:[NSString stringWithFormat:#"http://www.website.com/page.php?status=%#", status]]]];
+[NSURLRequest requestWithURL:] is expecting you to give it an NSURL object. You're giving it an NSString. Don't do that. :)
NSString *urlAddress = [NSString stringWithFormat:#"http://www.website.com/page.php?status=%#", status];
//Create a URL object.
NSURL *url = [NSURL URLWithString:urlAddress];
//URL Requst Object
NSURLRequest *requestObj = [NSURLRequest requestWithURL:url];
//Load the request in the UIWebView.
[webView loadRequest:requestObj];
Use this:
[webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:[NSString stringWithFormat:#"http://www.website.com/page.php?status=%#", status]]]];

UIWebView and Safari content not looking the same

I have a UIWebView which is adapted to a mobile style of a forum I have. In Safari, it looks and works great.
However, inside my WebView there is a disastrous problem.
When quoting or editing a post, HTML is displayed inside of BBcode. Furthermore, posting code results in ignored line breaks.
The webview is loaded like this:
//display the webview
NSString *fullURL = #"http://www.mysite.com";
NSURL *url = [NSURL URLWithString:fullURL];
NSMutableURLRequest *requestObj = [NSMutableURLRequest requestWithURL:url];
[_webTest loadRequest:requestObj];
Change your this line:
NSMutableURLRequest *requestObj = [NSMutableURLRequest requestWithURL:url];
With this line & check:
NSURLRequest *requestObj = [NSURLRequest requestWithURL:url];
Do you want to load a html-string in your webView?
If it is the thing than following may help you:
NSString *bundlePath = [[NSBundle mainBundle] bundlePath];
NSURL *baseURL = [NSURL fileURLWithPath:bundlePath];
NSString *htmlString = [bundlePath pathForResource:#"index" ofType:#"html"] ;
[webView loadHTMLString:htmlString baseURL:baseURL];

UIWebView: how do I start from a blank view each time?

I'm looking up web pages using UIWebView and NSURLRequest and it's working fine, but I want it to start with a blank page each time, rather than displaying the results of the last URL lookup. Is there an easy way to do that?
I'm doing this in viewDidLoad:
wikiText = [[[UIWebView alloc] initWithFrame:CGRectMake(0, 0, 320, 370)] autorelease];
[wikiView addSubview:wikiText];
...and then I load the UIWebView like this:
NSString *urlAddress =[NSString stringWithFormat: #"http://%#", randomEWiki];
NSURL *url = [NSURL URLWithString:urlAddress];
NSURLRequest *requestObj = [NSURLRequest requestWithURL:url];
[wikiText loadRequest:requestObj];
Start with this first.
[wikiText loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:#""]]];
This loads a blank page first. then open your usual URL.
NSString *urlAddress =[NSString stringWithFormat: #"http://%#", randomEWiki];
NSURL *url = [NSURL URLWithString:urlAddress];
NSURLRequest *requestObj = [NSURLRequest requestWithURL:url];
[wikiText loadRequest:requestObj];
We can also use Html tags like this
[wikiText loadHTMLString:#"<html><head></head><body></body></html>" baseURL:nil];
Then after you can load your actual url
NSString *urlAddress =[NSString stringWithFormat: #"http://%#", randomEWiki];
NSURL *url = [NSURL URLWithString:urlAddress];
NSURLRequest *requestObj = [NSURLRequest requestWithURL:url];
[wikiText loadRequest:requestObj];
There is no need to load load blank URL, you just use viewWillAppear, according to this, every time when your view will appear then webView will load your page and initially gives you white blank page then your url page.
-(void)viewWillAppear:(BOOL)animated
{
wikiText = [[[UIWebView alloc] initWithFrame:CGRectMake(0, 0, 320, 370)] autorelease];
[wikiView addSubview:wikiText];
NSString *urlAddress =[NSString stringWithFormat: #"http://%#", randomEWiki];
NSURL *url = [NSURL URLWithString:urlAddress];
NSURLRequest *requestObj = [NSURLRequest requestWithURL:url];
[wikiText loadRequest:requestObj];
}

uiwebview is not showing PDF properly as showing in safari

I am having a strange issue. UIwebview is not showing PDF file properly as it shows when I load the PDF file from web URL or in safari browser.
http://www.winsolz.com/temp/2.jpg
I am using the following code to open the PDF from local system.
NSString *pathFOrPDF = [[NSBundle mainBundle] pathForResource:[NSString stringWithFormat:#"Page%#", strPDFNumber] ofType:#"pdf"];
NSURL *targetURL = [NSURL fileURLWithPath:pathFOrPDF];
NSURLRequest *request = [NSURLRequest requestWithURL:targetURL];
[myWebview loadRequest:request];
[myWebviewLandscape loadRequest:request];
Thanks.
I don't think it would fix your case but I had a pdf showing in safari and not showing in a UIWebView and my problem was that the file extension was not correct. I appended a .pdf at the end of the local file url and started working.
I've noticed that safari check also content types so maybe it is working on safari as you provide a remote url?
this might help.
UIWebView *webView = [[UIWebView alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
webView.backgroundColor = [UIColor redColor];
NSString*fileName= #"About_Downloads";
NSString *path = [[NSBundle mainBundle] pathForResource:fileName ofType:#"pdf"];
NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL fileURLWithPath:path isDirectory:NO]];
[webView setScalesPageToFit:YES];
[webView loadRequest:request];
[self.view addSubview:webView]

How to show a PDF page by page using horizontal swipe in iphone?

I would like to add to my app a pdf viewer which can scroll horizontally. Anyone know how to do it? I'm making several attempts but without success. Thanks. Matteo
Use UIWebViewController in landscape orientation and this piece of code can give you an idea about how to display pdfs:
UIWebView *webView = [[UIWebView alloc] initWithFrame:CGRectMake( 0, 0, 320, 480 )];
NSString *path = [[NSBundle mainBundle] pathForResource:#"about" ofType:#"pdf"];
NSURL *targetURL = [NSURL fileURLWithPath:path];
NSURLRequest *request = [NSURLRequest requestWithURL:targetURL];
[webView loadRequest:request];
webView.scalesPageToFit = YES;
[self.view addSubview:webView];
[webView release];