Change textcolor of UIWebView

ketansahasrabudhe picture ketansahasrabudhe · Jul 2, 2012 · Viewed 12.5k times · Source

I am making an epub reader, into which I am loading HTML pages in my webview:

[_webview loadRequest:[NSURLRequest requestWithURL:[NSURL fileURLWithPath:_pagesPath]]];

Now I want to change background color and and text color of my the HTML pages. I changed background color of my webview using,

self._webview.backgroundColor = [UIColor blackColor];
self._webview.opaque = NO;

That's working, but I also want to change the text color of my webview. How do I do this?

Answer

Deepesh picture Deepesh · Jul 2, 2012

In this this code color:#fff tag use for text color #fff use black color

NSString *webStr =@"Your text use";

[self._webview  loadHTMLString:[NSString stringWithFormat:@"<div id ='foo' align='left' style='line-height:18px; float:left;width:300px; font-size:13px;font-family:helvetica;background-color:transparent; color:#fff;>%@<div>",webStr] baseURL:nil]; 

if you use local html the use

 NSString *htmlFile = [[NSBundle mainBundle] pathForResource:@"sample" ofType:@"html"];

NSString* text = [NSString stringWithContentsOfFile:htmlFile encoding:NSUTF8StringEncoding error:nil];
NSLog(@"%@",htmlFile);

NSLog(@"Hello");

[self._webview  loadHTMLString:[NSString stringWithFormat:@"<html><body bgcolor=\"#000000\" text=\"#FFFFFF\" face=\"Bookman Old Style, Book Antiqua, Garamond\" size=\"5\">%@</body></html>", text] baseURL: nil];