这是我的代码:
CGRect frame9 = CGRectMake(392, 100, 320, 329);
UIWebView * webView = [[UIWebView alloc] initWithFrame:frame9];
[webView setBackgroundColor:[UIColor clearColor]];
NSString* htmlContentString = [NSString stringWithFormat:
@"<html>"
"<style type=\"text/css\">"
" body {background-color:transparent; font-family:Helvetica; color: #c8b981 ; font-size:18px;text-align :justify;} .titulo {background-color:transparent; font-family:Helvetica; color: #42382b ; font-size:11px;}"
"</style>"
"<body>"
"<p class = titulo > %@ </p>"
"<p>%@</p>"
"<p2 { background-color:transparent; font-family:Helvetica; color: #42382b ; font-size:11px;text-align :left};> %@ </p2>"
"<p>%@</p>"
"<h2 style =background-color:transparent; font-family:Helvetica; color: #42382b ; font-size:11px;text-align :left;> %@ </h2>"
"<p>%@</p>"
"</body></html>",@"A LA VISTA", vino.vista,@"POR LA NARIZ" ,vino.nariz,@"AL PALADAR" , vino.paladar];
[webView loadHTMLString:htmlContentString baseURL:nil];
webView.backgroundColor = [UIColor clearColor];
[webView setOpaque:NO];
webView.scrollView.bounces = NO;
[subview addSubview:webView];
我想要做的是为身体选择一种风格,为标题设置一种风格但不起作用..
由于
答案 0 :(得分:2)
看起来您的HTML需要一些工作。尝试使用p标签的类。我认为这就是你想要的。
NSString *htmlString = @"<html><style type='text/css\'> body { background-color:transparent; font-family:Helvetica; color: #c8b981; font-size:18px;text-align:justify} .class1 { background-color:transparent; font-family:Helvetica; color: #0000FF; font-size:11px; } .class2 { background-color:transparent; font-family:Helvetica; color: #FF0000 ; font-size:11px; }' </style><body> <p class='class1'> Class1 </p><p class='class2'> Class2 </p><p> No Class </p></body></html>";
[webView loadHTMLString:htmlString baseURL:nil];