Reputation: 143
I am trying to draw a basic circle with SVG inside of an Html 5 file and then load that inside of a UIWebview. However when I compile and run nothing appears on screen (testing on iPad).
Am I not using the correct code or is SVG with Html 5 not supported in UIWebview?
Here is the code for the 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];
}
Here is the code inside the SVG.html file that is called in the resources folder:
<!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>
I have been reading through many related posts but I have not been able to puzzle out the answer.
Any help is appreciated. Thanks.
Upvotes: 2
Views: 4426
Reputation: 1753
That's because Safari (or what's inside UIWebView) has problems with embedded SVG elements. I heard that Apple is going to fix it, anyway...
Try this:
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>
circle.svg :
<svg xmlns="http://www.w3.org/2000/svg">
<circle r="50"/>
</svg>
Upvotes: 3