Mutawe
Mutawe

Reputation: 6524

How to implement a method for changing font color in UIWebView

In my app i have a UIWebView having a content from file (HTML)

im wondering if there is any way to let the user changing the font color form 5 colors or something like that

Any way??

Upvotes: 1

Views: 679

Answers (1)

Andy
Andy

Reputation: 30135

Do you want to change it from the app (objective-c) or the html?

You could create a javascript function inside your html file which changes the font (by changing a class on the body tag for example).

If you want to change it from the app you can call the function with:

[webView stringByEvaluatingJavaScriptFromString:@"changeColor('red')"];


something like this should work.

CSS

.red{
   color:#f00;
}
.green{
   color:#0f0;
}
.blue{
   color:#00f;
}

JS

function changeColor(colorClass){ // red, green or blue
    document.body.className = colorClass; 
}

Example

http://jsfiddle.net/mMhwC/

Upvotes: 1

Related Questions