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> & <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=@"third";
//create a webview
UIWebView *webview = [ init];
//create a empty html file and convert the svg into html and save dynamically
NSString *testPath = [pathForResource:@"test"ofType:@"html"inDirectory:nil ];
NSString *filePath = ] toFile:testPath];
//load svg file into the webview
//NSString *path = [ pathForResource:@"loadSVG" ofType:@"html"];
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 = @"https://code.jquery.com/jquery-3.2.1.min.js";
NSString *idOfJQuery = @"test";
NSString *type = @"image/svg+xml";
NSString *id = @"test";
return ).bind('click', function() {\nwindow.clickedId = $(this).attr('id');\n});\n}});\n});\nfunction clicked(){\n return window.clickedId;\n}</script>\n</head>\n<body>\n<embed src='%@' type='%@' id='%@'/>\n</body>\n</html>", jQueryLib,idOfJQuery,svgFileName,type,id];
}
- (void)tapAction:(UITapGestureRecognizer *)sender{
;
}
-(void)getJSObj{
NSLog(@"return value :%@",);
}
//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:@"testHtml.html"];
NSString *testPath = [pathForResource:svgName ofType:@"svg"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]