xcode 如何在 iphone 的 uiwebview 中更改文本颜色

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/7441320/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-14 21:56:52  来源:igfitidea点击:

how to change the text color in uiwebview in iphone

objective-cxcode

提问by kingston

I am parsing an rss feed and showing it in a webview I have set the background color of the webview as black using an image view.The parsed data is stored in a NSString...what I want is to change the textcolor,fontsize,fonttype of the string data..

我正在解析一个 rss 提要并在 webview 中显示它我已经使用图像视图将 webview 的背景颜色设置为黑色。解析的数据存储在 NSString 中......我想要的是更改文本颜色、字体大小、字符串数据的字体类型..

self.itemTitle.text=[item objectForKey:@"title"];

[self.itemSummary loadHTMLString:[item objectForKey:@"description"] baseURL:nil];
[self.itemSummary setClipsToBounds:YES];

self.itemSummary.opaque=NO;

self.itemSummary.backgroundColor=[UIColor clearColor];

回答by Infinite Possibilities

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

You can use HTML colors.

您可以使用 HTML 颜色。



Edit: added the text color.

编辑:添加了文本颜色。



Edit 2: added font size and face

编辑 2:添加字体大小和字体

回答by Eshwar Chaitanya

To change the text/font/content color in UIWebView,you can use CSS Style property as suggested here,i.e.:

要更改 UIWebView 中的文本/字体/内容颜色,您可以使用此处建议的 CSS 样式属性 ,即:

[self.itemSummary loadHTMLString:[NSString stringWithFormat:@"<html><body p style='color:red' text=\"#FFFFFF\" face=\"Bookman Old Style, Book Antiqua, Garamond\" size=\"5\">%@</body></html>", [item objectForKey:@"description"]] baseURL: nil];

It worked for me,hope it also helps you,thanks :)

它对我有用,希望它也能帮助你,谢谢:)