Cross-Platform Images in Xamarin.Forms Using SVGs
For the last four months, I’ve been working on a fast-paced Xamarin.Forms project where almost every image used has been an SVG shared between both the iOS and the Android platform apps. And it has been glorious! If an early UI design needed a few pixels shaved or added to an image we were using, no new images were needed, let alone a handful of pixel-density variations on it. It was just the few lines of code or XAML to change the rendered size. (In fact, I’ve extended our use to include stretchable buttons by adding 9-slice SVG support.) With SVGs, you use one tiny XML file to render the resulting image at any size or for any screen density. TL;DR Put SVGs in a PCL as an EmbeddedResource build action Use an SVG control (I recommend TwinTechsForms.NControl.SvgImageView, but there are other choices.) Add an SvgImageView to your C# or XAML UI the the right assembly and resource path Without SVG Images Images on iOS and Android are normally managed in slightly different ways regarding naming and location. For better or worse, Xamarin.Forms continues using these image conventions, making a detour from the focus on cross-platform sharing. On a normal… Continue reading