How to change UIWebView or WKWebView default font

前端 未结 9 1298
陌清茗
陌清茗 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:42

    Here is my easy-to-use and easy-to-expand solution with more font settings:

    myHTMLLabel = [[UIWebView alloc] initWithFrame:CGRectMake(myX, myY, myWidth, myHeight)];
    
    myHTMLLabel.userInteractionEnabled=NO;
    myHTMLLabel.scalesPageToFit=NO;
    
    [myHTMLLabel setOpaque:NO];
    myHTMLLabel.backgroundColor = myBackColor;
    
    NSString *myHTMLText = [NSString stringWithFormat:@""
                            ""
                            " [text]"];
    
    myHTMLText = [myHTMLText stringByReplacingOccurrencesOfString: @"[text]" withString: myText];
    myHTMLText = [myHTMLText stringByReplacingOccurrencesOfString: @"[fontName]" withString: myFontName];
    myHTMLText = [myHTMLText stringByReplacingOccurrencesOfString: @"[fontSize]" withString: myFontSize];
    myHTMLText = [myHTMLText stringByReplacingOccurrencesOfString: @"[fontColor]" withString: myFontColorHex];
    myHTMLText = [myHTMLText stringByReplacingOccurrencesOfString: @"[textAlign]" withString: myFontAlign];
    
    
    NSLog(@"*** renderHTMLText --> myHTMLText: %@",myHTMLText);
    
    [myHTMLLabel loadHTMLString:myHTMLText baseURL:nil];
    

提交回复
热议问题