菜鸟教程小白 发表于 2022-12-12 13:25:51

javascript - 在 Obj C 中,如何添加 SVG 蓝图图像并从 UIWebView 渲染数据?


                                            <p><p>我已将 SVG 图像加载到 UIWebView 中,但没有发生从 SVG 图像的选择位置渲染数据的工作魅力。即使我被搜索了更多关于我没有得到任何关于这个功能的信息。同样,我尝试过 SVGKit,但我不了解 SVGKit 的完整场景,所以我选择 UIWebView 的原因。如果有人知道这个功能,请在此处发表评论。 </p>

<blockquote>
<p>the SVG map seems like below one.i found few link about SVG image but those are not loading by UIWebView. <a href="https://github.com/SVGKit/SVGKit" rel="noreferrer noopener nofollow">SVGKIT</a> &amp; <a href="https://github.com/chensheng12330/SVGKitDemo" rel="noreferrer noopener nofollow">chensheng12330/SVGKitDemo</a></p>
</blockquote>

<p> <a href="/image/K9DdB.jpg" rel="noreferrer noopener nofollow"><img src="/image/K9DdB.jpg" alt="enter image description here"/></a> </p></p>
                                    <br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
                                            <p><pre><code>//Create a empty test.html and override below html code and reload the Webview.   
   -(UIWebView *)setup{
      self.svgName=@&#34;third&#34;;
      //create a webview
      UIWebView *webview = [ init];
      //create a empty html file and convert the svg into html and save dynamically
      NSString *testPath = [pathForResource:@&#34;test&#34;ofType:@&#34;html&#34;inDirectory:nil ];
      NSString *filePath = ] toFile:testPath];
      //load svg file into the webview
      //NSString *path = [ pathForResource:@&#34;loadSVG&#34; ofType:@&#34;html&#34;];
      NSURL *fileURL = [ initFileURLWithPath:filePath];
      NSURLRequest *req = ;
      [ webview loadRequest:req];
      [ webview setScalesPageToFit:YES];
      ;
       // webview.contentMode = UIViewContentModeScaleAspectFit;
      ];
      webview.delegate = self;
      return webview;
    }
    //HTML file
    -(NSString *)getHTMLStringForLoadSVG :(NSString *)svgFileName{
      NSString *jQueryLib = @&#34;https://code.jquery.com/jquery-3.2.1.min.js&#34;;
      NSString *idOfJQuery = @&#34;test&#34;;
      NSString *type = @&#34;image/svg+xml&#34;;
      NSString *id = @&#34;test&#34;;
      return ).bind(&#39;click&#39;, function() {\nwindow.clickedId = $(this).attr(&#39;id&#39;);\n});\n}});\n});\nfunction clicked(){\n return window.clickedId;\n}&lt;/script&gt;\n&lt;/head&gt;\n&lt;body&gt;\n&lt;embed src=&#39;%@&#39; type=&#39;%@&#39; id=&#39;%@&#39;/&gt;\n&lt;/body&gt;\n&lt;/html&gt;&#34;, jQueryLib,idOfJQuery,svgFileName,type,id];
    }
    - (void)tapAction:(UITapGestureRecognizer *)sender{
      ;
    }
    -(void)getJSObj{
      NSLog(@&#34;return value :%@&#34;,);
    }


    //write the code of converting svg to html code dynamically
    - (NSString *)writeAndAppendString:(NSString *)str toFile:(NSString *)fileName {
      NSData *data = ;
      NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
      NSFileManager *fileManager = ;
      if () {
            NSString *testP = [ stringByAppendingPathComponent:@&#34;testHtml.html&#34;];
            NSString *testPath = [pathForResource:svgName ofType:@&#34;svg&#34;inDirectory:nil ];
            NSString *testSvgP = [ stringByAppendingPathComponent:];
            [ copyItemAtPath:testPath toPath:testSvgP error:nil];
            [ copyItemAtPath:fileName toPath:testP error:nil];
            // Add the text at the end of the file.
            NSFileHandle *fileHandler = ;
            //;
            ;
            ;
            return testP;
      }
      return nil;
    }
</code></pre></p>
                                   
                                                <p style="font-size: 20px;">关于javascript - 在 Obj C 中,如何添加 SVG 蓝图图像并从 UIWebView 渲染数据?,我们在Stack Overflow上找到一个类似的问题:
                                                        <a href="https://stackoverflow.com/questions/43830427/" rel="noreferrer noopener nofollow" style="color: red;">
                                                                https://stackoverflow.com/questions/43830427/
                                                        </a>
                                                </p>
                                       
页: [1]
查看完整版本: javascript - 在 Obj C 中,如何添加 SVG 蓝图图像并从 UIWebView 渲染数据?