Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Change textcolor of UIWebView

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?

like image 228
ketansahasrabudhe Avatar asked Jul 02 '12 10:07

ketansahasrabudhe


2 Answers

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];
like image 144
Deepesh Avatar answered Sep 22 '22 14:09

Deepesh


[_webview loadHTMLString:[NSString stringWithFormat:@"<html><body style=\"background-color: white; font-size: 17; font-family: HelveticaNeue; color: #ffffff\">%@</body></html>", strDataFromHTML] baseURL: nil]; 
like image 40
Anil Kothari Avatar answered Sep 21 '22 14:09

Anil Kothari