在Iphone SDK中更改Web视图的字体大小

时间:2012-12-14 11:08:36

标签: iphone html ios xcode uiwebview

我实现了feed解析&将内容作为字符串。现在,我正在通过它进行html文件编程。在Web视图中加载该HTML。我的网络视图是表视图单元格中的子视图。

enter image description here

但是现在我想更改网页视图内容的字体大小,以便用户可以看到一些细节。

我的HTML生成代码是:

NSString * postHTML=[[_parseResults objectAtIndex:indexPath.row]valueForKey:@"summary"];

 NSString *close =[NSString stringWithFormat:@"</body></html>"];

    NSString *HTMLString = [NSString stringWithFormat:@"%@%@", postHTML,close];

    [Web_view loadHTMLString:HTMLString baseURL:nil];

[cell.contentView addSubview:Web_view];

return cell;

如何更改网页浏览量内容的字体大小?

3 个答案:

答案 0 :(得分:9)

[myWeb loadHTMLString:[NSString stringWithFormat:@"<div style='text-align:justify; font-size:45px;font-family:HelveticaNeue-CondensedBold;color:#0000;'>%@%@",postHTML,close] baseURL:nil];

您可以在字体大小中设置字体大小:代码中的大小。

尝试这个..我知道它是否有效!!!

答案 1 :(得分:4)

在UIWebView中,您可以在传递数据时使用所有HTML标记。

[WebView loadHTMLString:[NSString stringWithFormat:@"<div style='text-align:justify; font-size:44px;font-family:HelveticaNeue-CondensedBold;color:#ffff;'>%@",Data] baseURL:nil];

使用上面的代码,其中“数据”将是您的内容。

谢谢,

Hemang。

答案 2 :(得分:1)

在你的html中设置

NSString *string = [NSString stringWithFormat:
                        @"<html> \n" "<head> \n"
                        "<style type=\"text/css\"> \n"
                        "body {font-family: \"%@\"; font-size: %@;}\n"
                        "</style> \n"
                        "</head> \n"
                        "<body>%@</body> \n"
                        "</html>",@"Helvetica",[NSNumber numberWithInt:17],
                        @"<p><i>My data</p>"];