blank screen appear few millisec before uiwebview display local HTML page - iphone

I have a UINavigationController that display a table view. When I click on a row then I push a new view on the stack that contains a UIWebView.
Inside the View Controller I load a local HTML page in the UIWebView. It works fine except that the first time the app is started when the UIWebView is displayed there is a blank white screen that is pushed during 1 sec before to really display the HTML content.
Next times the blank white screen is displayed also but only few millisecond.
How can I do to avoid this blank white screen before the HTML is displayed?
Here's the code I'm using to display the HTML file in the uiWebView.
NSString *localizedAboutHTML = NSLocalizedString(#"About", #"Filename of the HTML page to be displayed depending on the language");
NSString *path = [[NSBundle mainBundle] pathForResource:localizedAboutHTML ofType:#"html"];
NSURL* baseURL = [NSURL fileURLWithPath:path];
NSFileHandle *readHandle = [NSFileHandle fileHandleForReadingAtPath:path];
NSString *htmlString = [[NSString alloc] initWithData:
[readHandle readDataToEndOfFile] encoding:NSUTF8StringEncoding];
webView.opaque = YES;
webView.backgroundColor = [UIColor blackColor];
[self.webView loadHTMLString:htmlString baseURL:baseURL];
[super viewWillAppear:animated];
Thanks,
Séb.

Because WebView loading can take longer, depends on your HTML file. If you don't want to show white screen appears for that short period of time why not Add activity indicator to show that webview is loading for users. One more option is hide webView and show it after webView loading is complete in webview delegate method webViewDidFinishLoad:(UIWebView *)webView

Related

JavaScript method is not getting called on web view in iOS

I have an HTML file and JS file in my app. When the web view is loaded I am loading my html file which contains the reference to JavaScript file. I have added the JavaScript file in to my bundle resource for compile sources and in the web view did finish load I am calling a JavaScript function which increases the font size of HTML content but the JavaScript method is not getting called.
This is my code:
NSString *readerstring = #"document.getElementById('reader')";
[webView stringByEvaluatingJavaScriptFromString:[[NSString alloc]initWithFormat:#"adjustFontSize('%#'.contentDocument, '4.0')",readerstring]];
You can change the font size of UIWebView like this,
int fontSize = 20;
NSString *String = [[NSString stringWithFormat:#"document.getElementsByTagName('body')[0].style.webkitTextSizeAdjust= '%d%%'", fontSize];
[myWebView stringByEvaluatingJavaScriptFromString:jsString];
or
[myWebView stringByEvaluatingJavaScriptFromString: #"document.body.style.fontSize = '8px'"];
Hope it will helps you...
Call the JS function after web view finished its loading.
And if you are using any of jQuery functions don forget to add jquery.js and evaluate it.
-(void)webViewDidFinishLoad:(UIWebView *)webView{
NSMutableString *jsStr =[[NSMutableString alloc] initWithData:[NSData dataWithContentsOfFile:[[NSBundle mainBundle] pathForResource:#"jquery.min" ofType:#"js"]] encoding:NSUTF8StringEncoding];
[WebView stringByEvaluatingJavaScriptFromString:jsStr];
jsStr =[[NSMutableString alloc] initWithData:[NSData dataWithContentsOfFile:[[NSBundle mainBundle] pathForResource:#"yourown" ofType:#"js"]] encoding:NSUTF8StringEncoding];
[WebView stringByEvaluatingJavaScriptFromString:jsStr];
//evalute your js file before calling its function
[WebView stringByEvaluatingJavaScriptFromString:#"myFunctionToChangethefontSize();"];
//change font size directly
[WebView stringByEvaluatingJavaScriptFromString:#"$('#divContent').css('font-size', '18px');"];
}
Important:
Check whether the JS file in compile resource bundle then you have to remove it from there and add it in copy Bundle Resource.

Best way to have article text with links on iPhone?

I am making an iPhone app that has a bunch of "articles" with certain words that I want to link to other "articles". I need to display the articles in UITableViewCells.
If there is a way to do this without a web view, that's great.
If I need to use a web view, should I just make <a href> style links? How can I have it jump to the article without creating a bunch of actual html pages, just have it let my program know that they clicked on that link and then the program goes and finds the appropriate article from a plist or something?
I've create a test demo using UIWebView and it works fine.
Create two HTML files:home.html and first.html.
// home.html
Home page. first
// first.html
First page. home
//viewDidLoad
self.webView.delegate = self;
NSString *htmlFilePathString = [[NSBundle mainBundle] pathForResource:#"home" ofType:#"html"];
NSURL *htmlFileURL = [[NSURL alloc] initFileURLWithPath:htmlFilePathString];
NSURLRequest *request = [[NSURLRequest alloc] initWithURL:htmlFileURL];
[self.webView loadRequest:request];
// webView's delegate:
- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType
{
return YES;
}

Sending Colored Text Messages in iPhone

I am working on iPhone App similar to Pimp My text available here:
http://itunes.apple.com/us/app/pimp-my-text-send-color-text/id489972714?mt=8
I am trying to find a way for sending Colored and animated Messages as the app does.
I have tried this by using UIWebview but it seems the paste board is used in the app to send the iMessage but its not working. The paste board copies the message from editor screen of message and paste it to default iMessage controller. But I am not sure how it is done in the app.
Can anyone suggest any way to send the Colored, animated text with effects?
I have fixed this by following code:
UIPasteboard *pasteboard = [UIPasteboard generalPasteboard];
pasteboard.persistent = YES;
NSString *imagefile =app.strimagepath;
///
BOOL fileExists = [[NSFileManager defaultManager] fileExistsAtPath:imagefile];
if (fileExists)
{
NSData *data = UIImagePNGRepresentation([UIImage imageWithContentsOfFile:imagefile]);
pasteboard.image = [UIImage imageWithData:data];
}
NSString *phoneToCall = #"sms: 123-456-7890";
NSString *phoneToCallEncoded = [phoneToCall stringByAddingPercentEscapesUsingEncoding:NSASCIIStringEncoding];
NSURL *url = [[NSURL alloc] initWithString:phoneToCallEncoded];
[[UIApplication sharedApplication] openURL:url];
Here app.strimgPath is the path of image stored in document directory. when the MessageView is opened. Longpress and click on Paste and message will be pasted.
May be the question I asked did not clarified correctly as what I want. But the above was something that solved my purpose.

asy there any way to change color of UIWebView of Iphone Application

I am using webview to display Data from RSS Feed Can I change color of WebView to Black From white.
I have declare outlet in xib file named RemainingRssViewController
and i am diplaying it from root view controller the code is
NSString *htmlstring =[[blogEntries objectAtIndex: blogEntryIndex] objectForKey: #"description"];
NSURL *baseUrl;
baseUrl = [[NSURL alloc]initWithString:feedurl];
[anotherViewController.maintext loadHTMLString:htmlstring baseURL:baseUrl];
//maintext is the UIWebVeiw outlet in anotherViewController.
Ok, looks good.
With this code:
NSString *htmlstring =[[blogEntries objectAtIndex: blogEntryIndex] objectForKey: #"description"];
You set up an HTML string to go in the UIWebView. However, it's not actually HTML, because right now it's just text. To solve this, we'll instead make the "htmlstring" to be styled HTML with the text from the XML feed.
For example:
NSString *textString = [[blogEntries objectAtIndex: blogEntryIndex] objectForKey:#"description"];
NSString *htmlstring = [NSString stringWithFormat:#"<html><head><style type='text/css'>body { color:#FFFFFF; background-color: #000000; }</style></head><body>%#</body></html>",textString];
Then, when the "htmlstring" is placed inside the UIWebView, it will be styled as you would like it to be.

iPhone SDK: Preferences

I wanted an entire page of text(multiple lines) in my settings similar to the one on iphone:
settings->general settings->About->Legal
I have not been able to do so. I tried entering title in PSGroupSpecifier, it gives me multiple lines but with a gray background. i wanted a white background.
Any help would be highly appreciated.
Thanks in advance
Use a UIWebView and store your page as a HTML file in your resources.
// Create the UIWebView
UIWebView *webView = [[[UIWebView alloc] initWithFrame:self.view.frame] autorelease];
// Add the UIWebView to our view
[self.view addSubview:webView];
// Load the HTML document from resources
NSString *pagePath = [[NSBundle mainBundle] pathForResource:#"legal" ofType:#"html"];
NSURL *pageURL = [NSURL fileURLWithPath:pagePath];
NSURLRequest *pageReq = [NSURLRequest requestWithURL:pageURL];
[webView loadRequest:pageReq];