iOS Swift Add SVG Image to button like Android

Viewed 18115

In Android, we can import SVG as Vector XML, Use this as Drawable, Change colors of SVG Icons and add to button

void setSvgIcnForBtnFnc(Button setBtnVar, int setSvgVar, int setClrVar, String PosVar)
{
    Drawable DevDmjVar = getDrawable(setSvgVar);
    DevDmjVar.setBounds(0,0,Dpx24,Dpx24);
    DevDmjVar.setColorFilter(new PorterDuffColorFilter(setClrVar, PorterDuff.Mode.SRC_IN));
    switch (PosVar)
    {
        case "Tit" : setBtnVar.setCompoundDrawables(null, DevDmjVar, null, null); break;
        case "Rit" : setBtnVar.setCompoundDrawables(null, null, DevDmjVar, null); break;
        case "Pit" : setBtnVar.setCompoundDrawables(null, null, null, DevDmjVar); break;
        default: setBtnVar.setCompoundDrawables(DevDmjVar, null, null, null); break;
    }
}

How do I do this in swift for iphones ?

setBtnVar.setImage(<image: UIImage?>, forState: <UIControlState>)
5 Answers

I used Aleksey Potapov's answer. The conversion and everything is perfect! However I had an issue where my image was too large for my application.

So use this to resize it to a good size for ios development:

<svg xmlns="http://www.w3.org/2000/svg" height="30" width="30" viewBox="0 0 1000 1000" xmlns:xlink="http://www.w3.org/1999/xlink">

Check out my app: Speculid It will automatically convert SVGs into PDFs or PNGs depending on how your asset library is setup.

Related