zoukankan      html  css  js  c++  java
  • ios 修改webView字体

     UIFont *font = [UIFont systemFontOfSize:12];
        
        //方法一
        NSString *fontColor =@"CCCCFF";
        NSString *htmlString =[NSString stringWithFormat:@"<html> 
    "
                            "<head> 
    "
                            "<style type="text/css"> 
    "
                            "body {font-family: "%@"; color: %@;}
    "
                            "</style> 
    "
                            "</head> 
    "
                            "<body>%@</body> 
    "
                            "</html>", font.familyName,fontColor,self.html];
        //方法二
       NSString* htmlString = [NSString stringWithFormat:@"<span style="font-family: %@!important; font-size: %i">%@</span>",
                      font.fontName,
                      (int) font.pointSize,
                      self.html];
        //方法三
        NSString *htmlString = [NSString stringWithFormat:@"<font face='%@' >%@", font.fontName,self.html];
        
       //以上三种方法都需 提起获取到 html,然后用下面方法加载html
        [self loadHTMLString:htmlString baseURL:DDWebBaseURL];
    //方法4 也可以在webview中代理方法中修改  这种方法体验不好 
    - (void)webViewDidFinishLoad:(UIWebView *)webView {
    UIFont *font = [UIFont systemFontOfSize:14];        
    NSString *script = [NSString stringWithFormat:@"document.body.style.fontFamily = '%@'",font.familyName];
    [webView stringByEvaluatingJavaScriptFromString:script];
    }
    //通过修改DOM,修改特定节点的样式

        NSString *script1 = @"document.getElementsByClassName('component-item component-content')[0].getElementsByTagName('p')[0].style.fontSize='30px'";

        NSString *script = @"document.getElementsByClassName('component-item component-content')[0].getElementsByTagName('p')[0].style.fontFamily='DFWaWaW5'";

        NSString *html341 =[webView stringByEvaluatingJavaScriptFromString:script1];

        NSString *html34 =[webView stringByEvaluatingJavaScriptFromString:script];

     
  • 相关阅读:
    Linux 共享库
    使用Visual Studio(VS)开发Qt程序代码提示功能的实现(转)
    ZOJ 3469 Food Delivery(区间DP)
    POJ 2955 Brackets (区间DP)
    HDU 3555 Bomb(数位DP)
    HDU 2089 不要62(数位DP)
    UESTC 1307 windy数(数位DP)
    HDU 4352 XHXJ's LIS(数位DP)
    POJ 3252 Round Numbers(数位DP)
    HDU 2476 String painter (区间DP)
  • 原文地址:https://www.cnblogs.com/shanyimin/p/5771946.html
Copyright © 2011-2022 走看看