开发者

How to make a UIWebView show its text with a custom font?

开发者 https://www.devze.com 2023-01-17 16:00 出处:网络
It looks like if the font in UIWebView is by default some kind of \"Times New Roman\". I guess I would have to figure out what font apple uses for [UIFont systemFontOfSize:15] ... o开发者_运维技巧r is

It looks like if the font in UIWebView is by default some kind of "Times New Roman". I guess I would have to figure out what font apple uses for [UIFont systemFontOfSize:15] ... o开发者_运维技巧r is there some intelligent way to do it?


How are you inserting text in the UIWebView? Assuming you are setting the HTML you can change the font either by full CSS, inline CSS or deprecated font tags.

<html>
    <head>
        <style>
        BODY { font-family: 'Times New Roman'; font-size: 15px; }
        </style>
    </head>
    <body>
        Here is some text
    </body>
</html>

Of course tweak style and size appropriately.


[myWebView loadHTMLString:[NSString stringWithFormat:@"<html><head><style>BODY { font-family: 'Arial-Bold'; font-size: 16px; }</style></head><body>%@</body></html>",htmlBodyString] baseURL:nil];
0

精彩评论

暂无评论...
验证码 换一张
取 消