gpt4 book ai didi

html - 如何更改 loadedHtml 文本中的字体颜色

转载 作者:行者123 更新时间:2023-11-28 04:04:19 25 4
gpt4 key购买 nike

我已经保存了这样一个字符串..

NSString *loadString = [NSString stringWithFormat:@"<html><body><font color=\"white\">%@</font></body></html>", string];

现在我想使用 webview 加载这个字符串

[webView loadHTMLString:loadString baseURL:nil];

现在,当网页加载时,颜色默认为黑色。我想将颜色更改为白色,但我做不到。关于如何更改字体颜色的任何建议。谢谢。

编辑 1:我试过了,但没有运气..

NSString *htmlString = [NSString stringWithFormat:@"<html><style type=\"text/css\"><!--.style1 { font-family: Arial;color: #FFFFFF;font-size: 20px;font-weight: bold;}--> <body><font class=\"style1\">%@</font></body></html>", string];

还有这个..

NSString *htmlString = [NSString stringWithFormat:@"<html> \n""<head> \n""<style type=\"text/css\"> \n""body {font-family: \"%@\"; font-size: %@; color:#FFFFFF; }\n""</style> \n""</head> \n""<body>%@</body> \n""</html>", @"helvetica", [NSNumber numberWithInt:15], string];

最佳答案

这是完整的列表。只需创建一个名为“WebViewTestViewController”的 View Controller + NIB,然后将 webView 添加到你的 nib 文件中并连接它。

WebViewTestViewController.h:

#import <UIKit/UIKit.h>

@interface WebViewTestViewController : UIViewController {
UIWebView *webView;
}
@property (nonatomic, retain) IBOutlet UIWebView *webView;
@end

WebViewTestViewController.m:

#import "WebViewTestViewController.h"

@implementation WebViewTestViewController
@synthesize webView;

- (void)viewDidAppear:(BOOL)animated {
NSString *string = @"Hello world";
NSString *loadString = [NSString stringWithFormat:@"<html><head><style>body {background:blue} p {color:white;}</style></head><body><p>%@<p></body></html>", string];
[webView loadHTMLString:loadString baseURL:nil];

[super viewDidAppear:animated];
}

- (void)dealloc {
[webView release];
[super dealloc];
}


- (void)viewDidUnload {
[self setWebView:nil];
[super viewDidUnload];
}

@end

关于html - 如何更改 loadedHtml 文本中的字体颜色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6424568/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com