简体   繁体   中英

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??

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/

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM