Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Justify text in UIWebView on iPhone OS using inline CSS?

Using CSS in a UIWebView, how can I make left-to right text flow in a justified manner? What CSS am I looking for?

EXAMPLE

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

does not work. What goes instead of justify?

like image 347
Moshe Avatar asked Jan 19 '26 01:01

Moshe


1 Answers

just pasted from an old project. I do hope this helps

    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];
like image 88
marcio Avatar answered Jan 21 '26 18:01

marcio



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!