使用内联CSS在iPhone OS上的UIWebView中对齐文本?

时间:2010-05-07 21:18:57

标签: css iphone uiwebview mobile-safari

在UIWebView中使用CSS,如何以合理的方式制作从左到右的文本流?我在找什么CSS?

  

实施例

     

<p style='text-align: justify;'>

不起作用。是什么而不是justify

1 个答案:

答案 0 :(得分:11)

刚从一个旧项目粘贴。我希望这有帮助

    NSString *css = [NSString stringWithFormat:
                     @"<html><head><style>body { background-color: transparent; text-align: %@; font-size: %ipx; color: white;} a { color: #172983; } </style></head><body>", 
                     @"justify",
                     16];

    NSMutableString *desc = [NSMutableString stringWithFormat:@"%@%@<br><br>%@<br><br>%@%@", 
                             css,
                             sampleText,
                             sampleText,
                             sampleText,
                             @"</body></html>"];

    UIWebView *webView = (UIWebView *)[self viewWithTag:WEB_VIEW_TAG];
    [webView loadHTMLString:desc baseURL:nil];