我怎样才能设置HTML的字体和行距我加载到Web视图? [英] How can I set the font and line spacing on HTML I load into a webview?

查看:219
本文介绍了我怎样才能设置HTML的字体和行距我加载到Web视图?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个iOS应用程序解析来自远程rss提要的文章。

当我通过webview和LoadHTMLString:withURL格式化文本时,文本被格式化为一些默认的字体/行间距。我想设置我自己的字体/行间距,我认为这可以做到,如果我在每篇文章的开头包含正确的HTML格式代码作为字符串。

这样我就可以操作XCode来为我的喜好设置字符串的格式。



唯一的一点是,当我添加行

 < ; p style =font:20pt / 30pt Times New Roman,serif;> 

文本仍然没有格式化。我觉得这可能是因为它创建了一个无格式的段落,但也是零,所以没有检测到的变化。

解决方案

代码在一个段落中设置了一个段落,所以它不起作用,但是如果你把它设置为

  NSMutableString fontString = [NSMutableString stringWithFormat:@< div style = \font:20pt / 30pt Times New Roman,serif; \>%@< / div>,textFile]; 

反而,它工作正常。

I have an iOS app that parses articles from a remote rss feed.

When I format it through a webview and "LoadHTMLString:withURL," the text is formatted with some default font/line spacing. I want to set my own font/line spacing, and I think that this can be done if I include the correct HTML formatting code as a string in the beginning of each article.

This way I'll manipulate XCode to format the string for my liking.

The only thing is that when I add the line

<p style="font: 20pt/30pt Times New Roman, serif;">

The text still remains unformatted. I feel like this might be because it creates a nil paragraph which is formatted, but is also nil, so there is no detectable change.

解决方案

The code set a paragraph in a paragraph so it didn't work, but if you set it up as

     NSMutableString *htmlString = [NSMutableString stringWithFormat:@"<div style=\"font: 20pt/30pt Times New Roman, serif;\">%@</div>", textFile ];

instead, it works fine.

这篇关于我怎样才能设置HTML的字体和行距我加载到Web视图?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆