2011-04-27 36 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];