iPhone list style like UL LI - iphone

Is there a way to create a list style like the UL LI for HTML on the iPhone in a textView? Why i want this is because when i have a long text there will be minimal 2 rules text show.
Example:
Hello i'm a monkey
from the zoo!
Hello i'm a monkey
from the zoo!

Use UIWebView, you can pass it arbitrary HTML as a NSString.

the best way that worked for me is to use a UIWebView and add the text as HTML.
this is apple recommendation for rich text.
UIWebView *webview = [[UIWebView alloc] initWithFrame:CGRectMake(0, 130,300 ,230)];
webview.backgroundColor = [UIColor clearColor];
webview.opaque=NO;
webview.delegate=self;
NSString *text = #"<ul><li>item 1</li><li>item 2</li></ul>";
NSString *cssPath = [[NSBundle mainBundle] pathForResource:#"style" ofType:#"css"];
NSString *path = [[NSBundle mainBundle] bundlePath];
NSURL *baseURL = [NSURL fileURLWithPath:path];
NSString *html =[NSString stringWithFormat:#"<!DOCTYPE html><html lang=\"en\"><head><link rel=\"stylesheet\" href=\"%#\" type=\"text/css\" /></head><body>%#</body></html>",cssPath,text];
[webview loadHTMLString:html baseURL:baseURL];
[self addSubview:webview];
And don't forget to create the "style.css" file in your project.
good luck
shani

Related

Can’t Display A Microsoft Word.doc document on UIView Controller

I’m using the code below to display pdfs or filename.doc Microsoft Word documents. It works fine when I use a ofType:#:”pdf”, but my code crashes when I use ofType:#:”doc” or ofType:#:”docx”. The Word document is mostly text and a few url links. Any help appreciated.
NSString *path = [[NSBundle mainBundle] pathForResource:#"C9" ofType:#"doc"];
pdfUrl = [NSURL fileURLWithPath:path];}
[webView loadRequest:[NSURLRequest requestWithURL:pdfUrl]];
As per your code, it looks like you're already using a UIWebView.
Here is some code I've used in the past.
-(void)loadDocument:(NSString*)documentName inView:(UIWebView*)webView {
NSString *path = [[NSBundle mainBundle] pathForResource:documentName ofType:nil];
NSURL *url = [NSURL fileURLWithPath:path];
NSURLRequest *request = [NSURLRequest requestWithURL:url];
[webView loadRequest:request];
}
In viewDidLoad (change webView frame to whatever you need)..
UIWebView *webView = [[UIWebView alloc] initWithFrame:CGRectMake(10, 10, 200, 200)];
[self.view addSubview:webView];
[self loadDocument:#"file.doc" inView:webView];
Take a look at using QLPreviewController to display these document types.
For the crash, are you sure the file exists at the specified location? Check it's actually being copied to the bundle and that there is a file at that path / URL before you use it.

what is the wrong when loading local resource files in webview in iphone

I am trying to load local css and html files into WebView , but the web view displays the content of css file in webview as you see in the following image ..
objective-c code:
NSString *htmlPath= [[NSBundle mainBundle] pathForResource:#"index" ofType:#"html" inDirectory:NO];
//[webView loadRequest:[NSURLRequest requestWithURL:[NSURL fileURLWithPath:htmlPath]]];
// load css styles
NSString *cssPath = [[NSBundle mainBundle] pathForResource:#"css" ofType:#"css"];
NSData *cssData = [NSData dataWithContentsOfFile:cssPath];
NSString *cssString = [[NSString alloc] initWithData:cssData encoding:NSASCIIStringEncoding];
// load js
NSString *jsPath = [[NSBundle mainBundle] pathForResource:#"MyJS" ofType:#"js"];
NSData *jsData = [NSData dataWithContentsOfFile:jsPath];
NSString *jsString = [[NSString alloc] initWithData:jsData encoding:NSASCIIStringEncoding];
// compose full html page
NSString *pageContent = [NSString stringWithFormat:#"%#%#%#", cssString, jsString, htmlPath];
[webView loadHTMLString:pageContent baseURL:[NSURL URLWithString:#""]];
what is the problem ?
You must not use
[webView loadHTMLString:pageContent baseURL:[NSURL URLWithString:#""]];
instead loadHTMLString try to use stringByEvaluatingJavaScriptFromString
And if you have any problem check the following post. I think you will get it easily
UIWebView and local css file
I have not used it for CSS but hope this will help you...Good Luck...

Images not showing in device for Web view in iphone

I am working on one application. I stuck with one problem. I have HTML page and some images are in Resource Directory. Whenever i run the application on Simulator it works perfectly fine. But when i run the application on the device the image are not displaying but text is displaying only and instead of image Question mark is showing.
Code:
NSString *path = [[NSBundle mainBundle] pathForResource:#"test1" ofType:#"html"];
NSFileHandle *readHandle = [NSFileHandle fileHandleForReadingAtPath:path];
NSString *htmlString = [[NSString alloc] initWithData: [readHandlereadDataToEndOfFile]encoding:NSUTF8StringEncoding];
NSURL *baseurl = [NSURL fileURLWithPath:path];
[self.webView loadHTMLString:htmlString baseURL:baseurl];
HTML Code:
<img src="mainGrid.png">
Change your HTML code to (file:// tells that it's local resource):
<img src='file://%#'>
Then use it in this way:
NSString *pathToLocalImage = [[NSBundle mainBundle] pathForResource:#"mainGrid" ofType:#"jpg"];
NSString *content = [NSString stringWaithFormat:htmlString, pathToLocalImage];
[self.webView content baseURL:nil];

UIWebView loadHTMLString:baseURL method does not work

I want to show a local html string content in a UIWebView using this :
[webView loadHTMLString:value baseURL:[NSURL fileURLWithPath:[[NSBundle mainBundle] bundlePath]]];
I dont know what's going wrong, but the web view remains white
thank's for help
Try this
NSString *html = [[NSString alloc] initWithContentsOfFile:[[NSBundle mainBundle] pathForResource:#"document" ofType:#"html"]];
[webView loadHTMLString:html baseURL:nil];

The eXe-SCORM generated html file has to be transparent to show the backround UIIMage view

Hii....i am new to iPhone programming..Can anybody help me out please
i have an html which is generated by eXe tool.I need to show it on an UIImageView,created programmatically. so the html has to be transparent then the image looks like backround.
is it possible to make that html as transparent..?
Thank u
NSString *path = [[NSBundle mainBundle] pathForResource:#"filename" ofType:#"html"];
NSFileHandle *readHandle = [NSFileHandle fileHandleForReadingAtPath:path];
NSString *htmlString = [[NSString alloc] initWithData:
[readHandle readDataToEndOfFile] encoding:NSUTF8StringEncoding];
webView.opaque = NO;
webView.backgroundColor = [UIColor clearColor];
[self.webView loadHTMLString:htmlString baseURL:nil];
[htmlString release];
This code helped me
Thank u all...