• iOS 修改网络图片的大小 宽和高


    //image宽和高 好用
    NSString *strTemplateHTML = [NSString stringWithFormat:@"<html><head><style>img{max-320.0;height:auto !important;auto !important;};</style></head><body style='margin:0; padding:0;'>%@</body></html>", @"insert your html content here"];
    [webView loadHTMLString:strTemplateHTML baseURL:nil];
    //代理执行时调用
    网上给的下边的这个方法好像不太好用 我用了 没啥效果
    - (void)webViewDidFinishLoad:(UIWebView *)webView1 { //修改服务器页面的meta的值 就是文本的宽高 定义成 系统手机宽高 NSString *meta = [NSString stringWithFormat:@"document.getElementsByName("viewport")[0].content = "width=%f, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no"", webView.frame.size.width]; [webView1 stringByEvaluatingJavaScriptFromString:meta]; }

    我自己写了一个js ,有点麻烦 但是对图片管理的效果很明显

    如下代码:

    htmlText=[jsonObj objectForKey:@"content"];
    jsString = [NSString stringWithFormat:@"<html> 
    "
                                "<head> 
    "
                                "<style type="text/css"> 
    "
                                "body {font-size:%fpx; line-height:%fpx;background-color: transparent;}
    "
                              //  "img{max-305;height:auto !important;auto !important;};"
                                ".img {305.0;}"//关键是这句给所有网络图片设宽度
                                "</style> 
    "
                                "</head> 
    "
                                "<body>%@</body> 
    "
                                "</html>",  fontSize ,line_height,htmlText];
     NSURL *urlBai=[NSURL URLWithString:ImageWeb_Head];
                    [showWebView loadHTMLString:jsString baseURL:   urlBai];
                    showWebView.delegate=self;
    
    -(void)webViewDidFinishLoad:(UIWebView *)webView
    {
           [webView stringByEvaluatingJavaScriptFromString:
         @"var script = document.createElement('script');"
         "script.type = 'text/javascript';"
         "script.text = "function ResizeImages() { "
            "var imgs = document.getElementsByTagName('img');"
            
            "for (var i = 0; i < imgs.length; i ++) {"
            " var img = imgs[i];"
            " img.style.width = 305 ;"//图片宽度我设置为305
            " img.style.height = null;"
            "}"
         "}";"
         "document.getElementsByTagName('head')[0].appendChild(script);"];
        [webView stringByEvaluatingJavaScriptFromString:@"ResizeImages();"];
    }
  • 相关阅读:
    C. MP3(离散化 暴力)
    最大团、最小独立集
    欧拉函数
    In Touch(dijk+并查集优化)
    Path(2019 杭电多校第一场 ) hdu 6582(最短路模板+dinic模板)
    2019 南昌邀请赛 Winner (tarjan缩点)
    mybatis主键回填和自定义
    mybatis配置xml文件的层次结构
    Paratroopers
    Dual Core CPU
  • 原文地址:https://www.cnblogs.com/someonelikeyou/p/3598655.html
Copyright © 2020-2023  润新知