Is there a way to create a list style like the UL LI for HTML on the iPhone in a开发者_JAVA百科 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
精彩评论