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

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/13877470/
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-15 02:19:33  来源:igfitidea点击:

Change font size for web view in Iphone SDK

iphonehtmliosxcodeuiwebview

提问by user1673099

I have implementing feed parsing & get the content as a string. Now, I am making html file through it programetically. Load that HTML in the Web view. My web View is the subview in Table View cell.

我已经实现了提要解析并将内容作为字符串获取。现在,我正在以编程方式通过它制作 html 文件。在 Web 视图中加载该 HTML。我的 web 视图是表视图单元格中的子视图。

enter image description here

在此处输入图片说明

But Now i want to change the font size of web view content, so the user can see some detail .

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

My code for HTML generation is:

我的 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;
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;

How can i change font size of web view content??

如何更改 Web 视图内容的字体大小?

回答by NiravPatel

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

you can set font size in font-size:size in code.

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

try this..let me know it is working or not!!!

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

回答by Hemang

In UIWebView, you can use all HTML Tags while passing the data.

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

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

Use above code where "Data" will be your content.

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

Thanks,

谢谢,

Hemang.

赫芒。

回答by Rajneesh071

set in your html

在你的 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>"];