开发者

use viewport with svg, uiwebview iphone

开发者 https://www.devze.com 2023-03-01 08:11 出处:网络
in this page : http://developer.apple.com/library/safari/#documentation/appleapplications/reference/safarihtmlref/Articles/MetaTags.html

in this page : http://developer.apple.com/library/safari/#documentation/appleapplications/reference/safarihtmlref/Articles/MetaTags.html

it's explain how to use viewport to define default scale in a webpage for ios devices.

My probleme is that I want to display an SVG f开发者_开发百科ile on my uiwebview. I load my svg this way :

- (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];   

My svg is correctly loaded and displayed, but how can i use/insert this :

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

with a loadata to define the scale?

if it's not possible, is there a way with objectiveC to reset the zoom level after a click on the SVG file? Cause my scalePageToFit is true, so i need in some case to reset the zoom.

sorry for my english, thanks for your help


do you need that inserted into the svg's xml? I would load the svg file as a mutable string and use some matching find the proper location for it, and insert it at that location.

if you want that to be in document markup you should reference the svg in and html/xhtml/xml file.

    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];
0

精彩评论

暂无评论...
验证码 换一张
取 消