简体   繁体   中英

Set UIButton Image with SVG file

I'm trying to set the Image of my UIBUtton with a SVG file...the click on the button works fine but it appears invisible. I'm trying to use PocketSVG: https://github.com/arielelkin/PocketSVG

There's what I'm trying:

CGPathRef myPath = [PocketSVG pathFromSVGFileNamed:@"icon_convidar.svg"];

        //2: To display it on screen, you can create a CAShapeLayer
        //and set myPath as its path property:
        CAShapeLayer *myShapeLayer = [CAShapeLayer layer];
        myShapeLayer.path = myPath;


        //3: Fiddle with it using CAShapeLayer's properties:
        myShapeLayer.strokeColor = [[UIColor greenColor] CGColor];
        myShapeLayer.lineWidth = 4;
        myShapeLayer.fillColor = [[UIColor greenColor] CGColor];

        //4: Display it!
    [self.btnConvidar.layer addSublayer:myShapeLayer];

I only rewrite the line:

CGPathRef myPath = [PocketSVG pathFromSVGFileNamed:@"icon_convidar.svg"];

with the following line:

CGPathRef myPath = [PocketSVG pathFromSVGFileNamed:@"icon_convidar"];

You can't use SVG because iOS has no support for XML or SVG. PDF however will work. This is the best tutorial I have found on the subject: https://useyourloaf.com/blog/xcode-9-vector-images/

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM