开发者

iPhone list style like UL LI

开发者 https://www.devze.com 2023-02-04 05:25 出处:网络
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.

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:

  1. Hello i'm a monkey from the zoo!

  2. 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

0

精彩评论

暂无评论...
验证码 换一张
取 消