how to render svg file in iphone and ipad

浪子不回头ぞ 提交于 2019-12-25 04:47:19

问题


i wrote code to display any type of file like pdf,svg,etc.But unfortunately my code is working with only pdf.the code is like this

-(void)drawRect : (CGRect)rect {
CGPDFPageRef myPage;
NSString * pathToPdfDoc = [[NSBundle mainBundle] pathForResource:@ "pdfdoc" ofType:@ "pdf"];
NSURL * pdfUrl = [NSURL fileURLWithPath:pathToPdfDoc];
// NSLog(@"%@",pdfUrl);
CGPDFContentStreamRef myContentStream;
document = CGPDFDocumentCreateWithURL((CFURLRef)pdfUrl);
// NSLog(@"%@",[document description]);
if (document) {
    int numOfPages = CGPDFDocumentGetNumberOfPages(document);
    // NSLog(@"%d",numOfPages);
    CGPDFPageRef myPage = CGPDFDocumentGetPage(document, pgno);
    myContentStream = CGPDFContentStreamCreateWithPage(myPage);
    // CGPDFOperatorTableRef myTable;
    // myScanner = CGPDFScannerCreate (myContentStream, myTable, NULL);
    // CGPDFPageRef page = CGPDFDocumentGetPage(document, 1);
    // page = CGPDFDocumentGetPage(document, 2);
    CGContextRef ctx = UIGraphicsGetCurrentContext();
    CGContextSaveGState(ctx);
    CGContextTranslateCTM(ctx, 0.0, [self bounds].size.height);
    CGContextScaleCTM(ctx, 1.0, -1.0);
    CGContextConcatCTM(ctx,
                       CGPDFPageGetDrawingTransform(myPage, kCGPDFCropBox, [self bounds], 0, true));
    CGContextDrawPDFPage(ctx, myPage);
    CGContextRestoreGState(ctx);
}

}

initially i thought that if i change "pathForResources:ofType"method argument is svg it will works but it is not working, can any one suggest me modifications. thank you


回答1:


As per the comments to the question:

  • Learn more about using SVG images on the iPhone Check out SVG images in an iPhone application. The gist is, use a UIWebView,

  • SVG is not PDF




回答2:


Checkout

SVGKit SVGKit is a Cocoa framework for rendering SVG files natively: it's fast and powerful. https://github.com/SVGKit/SVGKit#readme



来源:https://stackoverflow.com/questions/4255976/how-to-render-svg-file-in-iphone-and-ipad

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!