Skip to content

hjaltij/SVGPathSerializing

 
 

Repository files navigation

SVGPathSerializing

A simple toolkit for reading reading/writing bezier paths to/from SVG. Only the path, polygon, & rectangle elements are supported.

The goal of this project is not to be a fully compatible SVG parser/renderer. But rather to use SVG as a format for serializing CG/UIPaths, meaning it only supports SVG features that can be represented by CG/UIPaths.

Screenshot

Basic Usage

    NSString *svgPath = [[NSBundle mainBundle] pathForResource:@"myImage" ofType:@"svg"];
    NSString *svgString = [NSString stringWithContentsOfFile:svgPath usedEncoding:NULL error:NULL];
    
    // Parse your SVG data
    for(id path in CGPathsFromSVGString(svgString, NULL)) {
        // Create a layer for each path
        CAShapeLayer *layer = [CAShapeLayer layer];
        layer.path = (__bridge CGPathRef)path;
        
        // Set its display properties
        layer.lineWidth   = 4;
        layer.strokeColor = [[UIColor blackColor] CGColor];
        layer.fillColor   = [[UIColor redColor] CGColor];
    
        // Add it to the layer hierarchy
        [self.view.layer addSublayer:layer];
    }

About

SVG to and from CGPaths

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Objective-C++ 59.7%
  • Objective-C 40.3%