开发者

How is a UIWebView's text color set?

开发者 https://www.devze.com 2023-01-16 08:38 出处:网络
I have been able to set the color of the background of my UIWebView, but not the textcolor. 开发者_StackOverflow中文版How can I set the text color?

I have been able to set the color of the background of my UIWebView, but not the textcolor.

开发者_StackOverflow中文版How can I set the text color?

I use this code

itemSummary.textColor = [UIColor colorWithRed:202 green:192 blue:146 alpha:0.75]; 

but get an request for member 'textColor' in something not a structure or union error.

Thanks


You can set the text color in HTML shown on UIWebView.


UIWebView doesn't have a method textColor. The only classes that I can see that do are: UITextField, UITableViewCell, UILabel and UITextField.

Because UIWebView inherits from UIView you can set the background color. To change the text you'll probably have to change the html of the page you're viewing.


You can set the color using standard css style as suggested here i.e.:

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

Hope it helps you and it worked perfect for me,thanks :)


I made a method that wraps some text in a HTML body with the correct style for a given UIColor and UIFont.

Simply pop the generated HTML into the webview:

NSString * htmlString = [MyClass htmlFromBodyString:@"an <b>example</b>"
                                           textFont:[UIFont systemFontOfSize:10]
                                          textColor:[UIColor grayColor]];
[webView loadHTMLString:htmlString baseURL:nil];


you can not set the text color in UIWebView directly. set text color in your HTML file load new HTML file in UIWebView.

0

精彩评论

暂无评论...
验证码 换一张
取 消