2011-04-27 32 views
2

在本页面:http://developer.apple.com/library/safari/#documentation/appleapplications/reference/safarihtmlref/Articles/MetaTags.html使用视使用SVG,UIWebView的iPhone

它解释如何使用视窗中针对iOS设备的网页来定义默认比例。

我的问题是我想在我的uiwebview上显示一个SVG文件。我载入我的SVG这样:

- (void)viewDidLoad { 

// Loading the SVG file from resources folder 
NSString *filePath = [[NSBundle mainBundle] 
         pathForResource:@"carteregionvin" ofType:@"svg"]; 
NSData *svgData = [NSData dataWithContentsOfFile:filePath]; 

NSString *resourcePath = [[NSBundle mainBundle] resourcePath]; 
NSURL *baseURL = [[NSURL alloc] initFileURLWithPath:resourcePath isDirectory:YES]; 

[self.webView loadData:svgData 
      MIMEType:@"image/svg+xml" 
      textEncodingName:@"UTF-8" 
      baseURL:baseURL]; 

我的SVG是正确加载和显示,但我怎么可以使用/插入此:

<meta name = "viewport" content = "initial-scale = 1.0"> 

与loadata定义规模有多大?

如果这是不可能的,是否有一种方法与ObjectiveC重置缩放级别后点击SVG文件?因为我的scalePageToFit是真的,所以我需要在某些情况下重置缩放。

对不起我的英语水平,

+0

你需要插入svg的xml吗?我会加载svg文件作为可变字符串,并使用一些匹配找到适当的位置,并将其插入到该位置。 – 2011-04-29 07:06:12

回答

0

你需要的是插入到SVG的XML感谢您的帮助?我会加载svg文件作为可变字符串,并使用一些匹配找到适当的位置,并将其插入到该位置。

如果你想要在文档标记中,你应该引用和html/xhtml/xml文件中的svg。

NSMutableString * svgString = [[NSMutableString alloc] initWithContentsOfFile:@"/some/path" encoding:NSUTF8StringEncoding error:nil]; 
    [svgString replaceOccurrencesOfString:@"<metadata" withString:@"<metadata \n<meta name = \"viewport\" content = \"initial-scale = 1.0\">" options:NSCaseInsensitiveSearch range:NSMakeRange(0, [svgString length])]; 
    NSData * svgData = [svgString dataUsingEncoding:NSUTF8StringEncoding];