gpt4 book ai didi

iphone - 带有内联 SVG 的 UIWebview Html5

转载 作者:塔克拉玛干 更新时间:2023-11-02 10:18:34 25 4
gpt4 key购买 nike

我正在尝试在 Html 5 文件中绘制一个带有 SVG 的基本圆,然后将其加载到 UIWebview 中。然而,当我编译并运行时,屏幕上什么也没有出现(在 iPad 上测试)。

我没有使用正确的代码还是 UIWebview 不支持带有 Html 5 的 SVG?

这是 UIWebview 的代码:

- (void)viewDidLoad 
{
[super viewDidLoad];

NSString* path = [[NSBundle mainBundle] pathForResource:@"SVG" ofType:@"html"];
NSString* content = [NSString stringWithContentsOfFile:path encoding:NSUTF8StringEncoding error:nil];

webView = [UIWebView new];
webView.frame = CGRectMake(0, 0, 1024, 768);
webView.dataDetectorTypes = UIDataDetectorTypeAll;
webView.userInteractionEnabled = YES;
[webView loadHTMLString:content baseURL:[[NSBundle mainBundle] bundleURL]];

[self.view addSubview:webView];
[webView release];
}

这是在资源文件夹中调用的 SVG.html 文件中的代码:

<!DOCTYPE html>
<head>
<title>SVG</title>
<meta charset="utf-8" />
</head>
<body>
<svg id="svgelem" height="200" xmlns="http://www.w3.org/2000/svg">
<circle id="redcircle" cx="50" cy="50" r="50" fill="red" />
</svg>
</body>
</html>

我已经阅读了许多相关的帖子,但我一直无法找到答案。

感谢任何帮助。谢谢。

最佳答案

那是因为 Safari(或 UIWebView 中的内容)在嵌入 SVG 元素时存在问题。听说苹果要修了,反正...
试试这个:

svg.html :

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>SVG</title>
</head>

<body>
<object data="circle.svg" width="250" height="250"
type="image/svg+xml" />
</body>
</html>

圆.svg :

<svg xmlns="http://www.w3.org/2000/svg">
<circle r="50"/>
</svg>

关于iphone - 带有内联 SVG 的 UIWebview Html5,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6977486/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com