How to change UIWebView or WKWebView default font

前端 未结 9 1299
陌清茗
陌清茗 2020-12-08 01:14

What font does UIWebView and WKWebView use by default? I would like to be able to change that. But I don\'t want to do it in the html string, inste

9条回答
  •  醉酒成梦
    2020-12-08 01:45

    You can use your UIFont object (so you can set it and modify more easily), but wrap the HTML in a span instead; font tags have been deprecated since HTML 4.01.

    UIFont *font = [UIFont fontWithName:@"GothamRounded-Bold" size:14];
    

    Assuming you already have the NSString *htmlString created, you can use the font's properties:

    htmlString = [NSString stringWithFormat:@"%@",
                                            font.fontName,
                                            (int) font.pointSize,
                                            htmlString];
    

    Alternatively, you could just supply the values instead of using a UIFont object:

    htmlString = [NSString stringWithFormat:@"%@",
                                            @"GothamRounded-Bold",
                                            14,
                                            htmlString];
    

提交回复
热议问题