How can I set the font and line spacing on HTML I load into a webview?

匆匆过客 提交于 2019-12-11 12:08:47

问题


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.


回答1:


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.



来源:https://stackoverflow.com/questions/14359339/how-can-i-set-the-font-and-line-spacing-on-html-i-load-into-a-webview

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!